feat(relinker): record the CPU extensions a conversion still needs #23279
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23279"
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 relativespace2K on 2026-11-18T21:43:24Z.
What
--to-avxoutput could not start on Linux or Windows, because only the macOS runtime skips the host CPU check; the other runtimes required every extension the lowering can remove. This records what the conversion still needs and checks only that..eh_framefunction ranges where the image has them, and undecodable bytes in a code segment record all seven extensions, so the scan can only over-require.--to-avxconversions the relinker takes the union over the lowered executable and the generated bundled modules, and writes it into the main executable: anAnyPS5PT_NOTEon Linux, a.aps5cpusection on Windows. Other conversions write no record and their bytes are unchanged.--to-avxno longer requires--macos.AVX2, F16C, FMA, PDEP, PEXT, RDRAND and RDSEED are still not lowered; a title that reaches one records that extension and is refused at start-up on a host that lacks it. F16C and FMA lowering are the follow-ups mentioned in the issue.
Tested
macOS 26.7.1, x86-64, AppleClang 17: relinker-only Release build, 883/883 CTest pass.
Linux (Pop!_OS, kernel 7.0), x86-64, Intel i5-8250U, GCC 11.4, CMake 3.22, git 2.56.1, node 22.23.5: relinker-only Release build in a git clone, 995/995 CTest pass.
The
HostCpuunit test was compiled and run on that Linux host, with stubs for the two libc log symbols it links. A test binary carrying the note with mask0lets a synthetic register set without AVX2 passCheckHostCpu; the same binary without the note still throws for AVX2. The relinker integration test checks the Linux note and the Windows section for VPGATHERDD (AVX2), VFMADD132PS (FMA), VCVTPH2PS (F16C), VADDPS (no requirement) and a NOP, and checks that a conversion without--to-avxwrites neither.The Windows reader was not executed, and no game title was converted with
--to-avx.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T21:46:09Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
0cbd3d4bab:tools/check_conventions.pypassed.cli_args_tests,host_cpu_tests,required_extensions_testsbuilt cleanly.host_cpu,required_extensions,cli_args):core/libs/prx/libkernel/System/include/HostCpu.hpp,core/libs/prx/libkernel/System/src/HostCpu.cpp,core/relinker/cli/src/CliArgs.cpp,core/relinker/elfpatcher/include/elfpatcher/general/IElfPatcher.hpp,core/relinker/elfpatcher/include/elfpatcher/general/IProgramHeaderLayoutBuilder.hpp,core/relinker/elfpatcher/include/elfpatcher/general/ProgramHeaderLayoutRequest.hpp,core/relinker/elfpatcher/include/elfpatcher/linux/LinuxElfPatcher.hpp,core/relinker/elfpatcher/include/elfpatcher/macos/MacOsMachOPatcher.hpp,core/relinker/elfpatcher/include/elfpatcher/windows/WindowsElfPatcher.hpp,core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp,core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp,core/relinker/elfpatcher/src/macos/MacOsMachOPatcher.cpp,core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp,core/relinker/relinker/include/relinker/guest/GuestImage.hpp,core/relinker/relinker/src/guest/GuestModuleBuilder.cpp,core/relinker/relinker/src/pipeline/Conversion.cpp,core/relinker/codegen/src/x86/RequiredExtensions.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T22:04:57Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make a required-extension record enforceable only when it is well formed and contains no unknown extension bits.
What I ran
Reviewed head
0cbd3d4babf4de56e657ef452d5f38c98190b732from the prepared diff and pinned reader. No build or tests were run.Results
Findings
Blocking
core/libs/prx/libkernel/System/src/HostCpu.cpp:153: the Linux note reader accepts a version 1 record with any mask bits, including bits outside the seven defined extensions.MissingHostCpuFeaturesonly uses known bits, so an unknown bit is silently ignored and can cause startup to skip a CPU feature check the record intended to require. Reject masks containing unknown bits and fall back to the full host check, consistent with the stated malformed-record behavior.Non-blocking
None.
Not verified
HostCpu.hpp,HostCpu.cpp,HostCputests, relinker CMake and CLI files,RequiredExtensions.hpp/.cppand tests, ELF/PE patcher interfaces and implementations, program-header layout builder,GuestImage.hpp,GuestModuleBuilder.cpp,Conversion.cpp, integration test, debt note, and usage documentation. Excluded files: none listed infiles.json.To get this to a good state
Reject unsupported extension mask bits and add coverage proving such a record falls back to the full CPU feature check. Re-run the relevant host CPU and relinker tests on the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T01:39:15Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: correct the extension scan so it cannot omit instructions outside recognized function ranges.
What I ran
Reviewed head
469dbdaf46474bece0c887b5f4718dc6b2dec3e1. No build or tests were run; the author reports test results in the PR description.Results
Findings
Blocking
core/relinker/codegen/src/x86/RequiredExtensions.cpp:214: WhencodeRangesis nonempty, the scanner visits only those ranges. Bytes outside the ranges are ignored, including executable code that has no.eh_framefunction entry. If such code contains an instruction the--to-avxconversion leaves requiring AVX2, FMA, or F16C, that extension is omitted from the record and libkernel can allow startup on a host that cannot execute it. Scan uncovered code conservatively, or fall back to requiring all extensions when function ranges do not cover the executable code.Non-blocking
None.
Sources
Not verified
No executable build or test run was performed. The Windows record reader was not executed and no game title was converted, as noted in the description. All changed files listed in the manifest were included; no changed files were excluded.
To get this to a good state
Cover executable bytes outside recognized function ranges conservatively, then rerun the relinker build and tests on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T02:15:07Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: validate PE header and section bounds before reading the CPU extension record.
What I ran
Reviewed head
c777fb0391e4359a0e716896853e12175b543ed5; no build or tests were run. Read the prepared description, commits, manifest and diff, then targeted source ranges throughrepo_read.py.Results
Findings
Blocking
core/libs/prx/libkernel/System/src/HostCpu.cpp:138-145: The Windows reader trustse_lfanew, the PE optional header, section count,VirtualSize, andVirtualAddressbefore dereferencing them. A malformed or truncated executable can make startup read outside the mapped image while looking for the record, rather than falling back to the full CPU check. Validate the DOS/NT header and section-table bounds againstSizeOfImage, and ensure the record’s 16 bytes fit in the mapped section before parsing.Non-blocking
None.
Not verified
No tests or builds were run. The description reports relinker test runs but the Windows reader was not executed and no game title was converted. All changed files listed in the manifest were included; targeted review focused on the CPU reader and extension-scanning implementation.
To get this to a good state
Validate PE image and section bounds before reading the record, then run the relevant Windows reader tests and relinker checks on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T02:33:48Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected code did not show a concrete blocking defect, but the review is incomplete, so a formal approval is not justified.
What I ran
Reviewed head
f21da9a7472abf38369ae99d57f312efb924cfa8. No build or tests were run; reported test results are from the PR description.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
The review bundle listed 24 changed files, all included in its manifest. I read targeted portions of six repository files:
core/libs/prx/libkernel/System/src/HostCpu.cpp,core/relinker/relinker/src/pipeline/Conversion.cpp,core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp,core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp,core/relinker/codegen/src/x86/RequiredExtensions.cpp, andcore/relinker/relinker/src/guest/GuestModuleBuilder.cpp. I did not read the remaining changed files or run the reported tests. The review bundle documents macOS and Linux test results; Windows reader execution and conversion of a game title were not confirmed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T18:51:21Z.
Review: COMMENTED
Reviewed — comments
The extension classifier under-reports requirements for valid AVX2 VEX instructions with a 128-bit vector length, so a generated record can let a host without AVX2 pass startup checks.
What I ran
Read the prepared description, commits, manifest, diff, and review-folder README for head
3b461b0e56cccde47d3508b2a4b1d9604da3d320. Inspected the changed classifier, conversion aggregation, PE metadata emission, ELF note emission, and host record parsing. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
core/relinker/codegen/src/x86/RequiredExtensions.cpp:222: WhenVector256is false, the classifier returns zero for most VEX opcodes unless explicitly listed. Several AVX2 instructions have 128-bit VEX forms too (for example,VPERMD/VPERMPSandVPSLLVD/VPSRLVD). If one occurs in converted code, the generated record omits AVX2, so a non-AVX2 host may pass the extension check and then fault when that instruction runs. Account for the 128-bit AVX2 forms by opcode and encoding, and add tests for representative XMM forms.Not verified
Builds, tests, physical-console behavior, the Windows startup reader, and full contents of the changed files outside the inspected ranges were not verified. Files read:
review/description.md,review/commits.md,review/manifest.json,review/diff.patch,review/README.md,core/relinker/codegen/src/x86/RequiredExtensions.cpp,core/relinker/relinker/src/pipeline/Conversion.cpp,core/relinker/relinker/src/guest/GuestModuleBuilder.cpp,core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp,core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp,core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp, andcore/libs/prx/libkernel/System/src/HostCpu.cpp. The other files listed as changed in the manifest were not read; all files were marked included there, and none were excluded.To get this to a good state
Nothing is required. Consider adding coverage for 128-bit AVX2 forms and ensuring they contribute the AVX2 bit.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T19:08:44Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: ensure a malformed matching CPU record cannot be ignored in favor of a later valid record, which can silently weaken the startup CPU check.
What I ran
Reviewed head
65f5ac8d10585e44aadea7b1a3f77afdac2d8df4against basemainusing the prepared diff and pinned repository reader. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
ParseCpuExtensionNotereturnsnulloptfor a malformed matching note, but continues scanning after malformed nonmatching note entries. If a malformed note has overflowing aligned sizes,offsetcan wrap before the bounds check and permit out-of-bounds parsing; note records are untrusted executable input. Consider overflow-safe alignment and offset arithmetic before advancing.core/libs/prx/libkernel/System/src/HostCpu.cpp:196nullopt; the full CPU check is retained as intended. However, malformed entries preceding a valid matching note are not consistently treated as a malformed whole record. This is a robustness concern in the parser; ensure malformed note structures terminate parsing safely.core/libs/prx/libkernel/System/src/HostCpu.cpp:195Not verified
Builds and tests were not run. The author reports passing test suites on macOS and Linux; those results were not independently confirmed. The Windows reader and converted game titles were not executed, as noted in the description. I reviewed the core CPU record parser, classifier, conversion aggregation, and Linux/Windows record emission paths. I did not read every added line in every changed file; full review completeness is therefore not established. The prepared bundle listed every changed file as included; no
files.jsonexclusion list was available through the reader.To get this to a good state
Nothing is required. Optional: make ELF note size/alignment arithmetic overflow-safe and reject malformed note structures consistently before scanning later records.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T20:52:25Z.
Review: COMMENTED
Reviewed — no blocking findings
The change records the CPU extensions still required after
--to-avxconversion; I found no verified blocking defect in the inspected code.What I ran
Reviewed head
370690471546786ba9a86b7d9f42a15e9238806cusing the prepared diff and repository reader. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The included changed files not read in full were
core/libs/prx/libkernel/System/include/HostCpu.hpp,core/libs/tests/HostCpu.cpp,core/relinker/CMakeLists.txt,core/relinker/cli/src/CliArgs.cpp,core/relinker/cli/tests/CliArgsTests.cpp,core/relinker/codegen/include/codegen/x86/RequiredExtensions.hpp,core/relinker/codegen/tests/RequiredExtensionsTests.cpp,core/relinker/elfpatcher/include/elfpatcher/general/IElfPatcher.hpp,core/relinker/elfpatcher/include/elfpatcher/general/IProgramHeaderLayoutBuilder.hpp,core/relinker/elfpatcher/include/elfpatcher/general/ProgramHeaderLayoutRequest.hpp,core/relinker/elfpatcher/include/elfpatcher/linux/LinuxElfPatcher.hpp,core/relinker/elfpatcher/include/elfpatcher/macos/MacOsMachOPatcher.hpp,core/relinker/elfpatcher/include/elfpatcher/windows/WindowsElfPatcher.hpp,core/relinker/elfpatcher/src/macos/MacOsMachOPatcher.cpp,core/relinker/relinker/include/relinker/guest/GuestImage.hpp,core/relinker/relinker/tests/test_required_extensions_record.py,docs/dev/debt/changes/required-extensions-record.md, anddocs/user/USAGE.md. The changed files read in full or relevant ranges werecore/libs/prx/libkernel/System/src/HostCpu.cpp,core/relinker/codegen/src/x86/RequiredExtensions.cpp,core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp,core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp,core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp,core/relinker/relinker/src/guest/GuestModuleBuilder.cpp, andcore/relinker/relinker/src/pipeline/Conversion.cpp. The prepareddescription.md,commits.md,manifest.json, anddiff.patchwere also read;files.jsonwas not available through the reader.To get this to a good state
Nothing is required. No optional points.
Pull request closed