Repository navigation
feat(relinker): record the host CPU features --to-avx output needs - #24915
momgaroganuchi-crypto wants to merge 6 commits into
Conversation
3bb1796 to
28ac604
Compare
|
Independent native Windows relinker verification with MSYS2 UCRT64 GCC 16.2 and Ninja. I applied the relinker diff and shared
AI-assisted: yes (OpenAI Codex). |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — comments
The review found a concrete host CPU feature classification gap that can let an AVX2 instruction run on a host without AVX2.
What I ran
Reviewed head 28ac60476a5f150bd0a2bdc9db8f15f455505fa4. I read the prepared description, commits, diff and manifest, and targeted classifier source. I did not run commands or tests.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | Classifier gap found |
| Tests | not run | No execution environment used |
Findings
Blocking
None verified.
Non-blocking
- The 128-bit AVX2-only opcode list omits AVX2 integer
VPACKUSDW(VEX.128.66.0F38.WIG 2B /r). The classifier returns no AVX2 bit for this instruction, so a retained occurrence can be absent from the record and pass the start-up check on a host without AVX2. Add the opcode toisAvx2Vector128and cover it with a classifier test. Evidence:core/relinker/codegen/src/x86/HostCpuFeatureClassifier.cpp:78.
Not verified
I read all changed files listed in the manifest as included, including classifier, conversion and test changes. No changed files were excluded. Tests and builds were not run; the author-reported CI and hardware results were not independently verified. I did not inspect unrelated repository context.
To get this to a good state
Nothing is required. The classifier coverage point above is optional feedback.
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 28ac60476a:
- Conventions:
tools/check_conventions.pypassed. - Build:
amd64_only_converter_tests,cli_args_tests,host_cpu_feature_classifier_tests,host_cpu_testsbuilt cleanly. - CTest (
host_cpu,host_cpu_feature_classifier,cli_args,amd64_only_converter):1/4 Test #5935: host_cpu ......................... Passed 0.03 sec 2/4 Test #6258: host_cpu_feature_classifier ...... Passed 0.01 sec 3/4 Test #6274: cli_args ......................... Passed 0.02 sec 4/4 Test #6288: amd64_only_converter ............. Passed 0.08 sec 100% tests passed, 0 tests failed out of 4 - Negative control: with
core/libs/prx/libc/include/ApplicationHeap.hpp,core/libs/prx/libc/src/ApplicationProcessParameters.cpp,core/libs/prx/libkernel/System/include/HostCpu.hpp,core/libs/prx/libkernel/System/src/HostCpu.cpp,core/relinker/cli/src/CliArgs.cpp,core/relinker/codegen/include/codegen/CodegenTypes.hpp,core/relinker/codegen/src/Amd64OnlyConverter.cpp,core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp,core/relinker/elfpatcher/include/elfpatcher/general/IElfPatcher.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/HostCpuFeatureClassifier.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass. - Code reading:
- Verified core/libs/prx/libc/src/ApplicationProcessParameters.cpp ApplicationHostCpuFeatures_nid_no_patch against buffer boundaries and dl_iterate_phdr mapping checks on Linux/Windows
- Checked core/libs/prx/libkernel/System/src/HostCpu.cpp HostCpuFeatures and CheckHostCpu logic with and without recorded features
- Analyzed core/relinker/codegen/src/x86/HostCpuFeatureClassifier.cpp instruction classification rules (VEX map/prefix matching, 256-bit AVX1 vs AVX2 opcodes, FMA, F16C, BMI1/2, MOVBE, LZCNT)
- Inspected core/relinker/codegen/src/Amd64OnlyConverter.cpp integration to ensure lowered instructions are excluded from RequiredHostCpuFeatures
- Verified core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp and LinuxElfPatcher.cpp PT_OS_HOSTCPU segment creation and slot bounds
Looks Good To Me
|
Added |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against e88c95e016:
- Conventions:
tools/check_conventions.pypassed. - Build:
amd64_only_converter_tests,cli_args_tests,host_cpu_feature_classifier_tests,host_cpu_testsbuilt cleanly. - CTest (
host_cpu,host_cpu_feature_classifier,cli_args,amd64_only_converter):1/4 Test #5963: host_cpu ......................... Passed 0.03 sec 2/4 Test #6304: cli_args ......................... Passed 0.02 sec 3/4 Test #6288: host_cpu_feature_classifier ...... Passed 0.01 sec 4/4 Test #6318: amd64_only_converter ............. Passed 0.09 sec 100% tests passed, 0 tests failed out of 4 - Negative control: with
core/libs/prx/libc/include/ApplicationHeap.hpp,core/libs/prx/libc/src/ApplicationProcessParameters.cpp,core/libs/prx/libkernel/System/include/HostCpu.hpp,core/libs/prx/libkernel/System/src/HostCpu.cpp,core/relinker/cli/src/CliArgs.cpp,core/relinker/codegen/include/codegen/CodegenTypes.hpp,core/relinker/codegen/src/Amd64OnlyConverter.cpp,core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp,core/relinker/elfpatcher/include/elfpatcher/general/IElfPatcher.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/HostCpuFeatureClassifier.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass. - Code reading:
- Verified ApplicationHostCpuFeatures_nid_no_patch dl_iterate_phdr parsing on Linux/Apple: validates p_type == 0x61000002, checks segment mapping within PT_LOAD boundaries, checks RecordSize (16 bytes), verifies magic APS5HCP1, and ensures reserved bits (~All) are zero.
- Verified Windows PE implementation in ApplicationProcessParameters.cpp: searches section headers for .hostcpu, validates VirtualSize == 16, boundary against imageSize, magic match, and non-duplicate section logic.
- Verified HostCpuFeatures and CheckHostCpu handling in libkernel HostCpu.cpp: correctly masks required status against recorded bits for Lzcnt, Bmi1, Bmi2, Movbe, Avx2, Fma, and F16c, and keeps baseline requirements intact when no record is present.
- Verified HostCpuFeatureClassifier.cpp instruction decoding and classifications for VEX 256-bit AVX1 vs AVX2, VEX 128-bit AVX2 forms (including VPACKUSDW), FMA, F16C, BMI1/2, MOVBE, and LZCNT legacy prefix / opcode rules.
- Verified Amd64OnlyConverter.cpp pipeline integration: matches are correctly classified, and instructions lowered via substitution, trampoline, or stub bodies are inserted into lowered set and excluded from RequiredHostCpuFeatures.
Looks Good To Me
ocr1n
left a comment
There was a problem hiding this comment.
On e88c95e016, --to-avx marks four instructions emitted by GCC for Sandy Bridge as requiring AVX2. That makes the startup check reject a supported CPU in exactly the use case in #22530. I put the correction and regression tests in a single commit on top of this PR. Apply or inspect the patch.
I converted the register and memory forms of each instruction separately. All eight fixtures produced an AVX2 mask of 0x10 in both ELF and PE. With the patch, all eight produce 0. A retained AVX2 gather, FMA and BMI2 instruction still produce 0x10, 0x20 and 0x04, respectively.
GCC 13.3 with -O2 -march=sandybridge emitted all four register forms. I checked their arithmetic under QEMU 8.2.2 with -cpu SandyBridge (CPUID reports AVX=1, AVX2=0). I also copied the generated ELF records into a Linux harness linked with this PR’s HostCpu.cpp and ApplicationProcessParameters.cpp. The original records produced “lacks AVX2” for all four. With the corrected records the harness ran to completion, and startup still rejected each of the three unsupported-instruction controls.
Both new regression expectations failed on this PR head. With the patch, all 1,061 relinker-only CTests passed on Ubuntu 24.04 under WSL2, along with the conventions check. Windows coverage was inspection of the generated PE records. No game title or physical Sandy Bridge machine was used.
AI-assisted: yes (OpenAI Codex).
| } | ||
|
|
||
| bool isAvx1Vector256(const std::uint8_t map, const std::uint8_t prefix, const std::uint8_t opcode) { | ||
| if (map == Map0F) { |
There was a problem hiding this comment.
The 256-bit forms of VCVTDQ2PD, VCVTPD2DQ and VCVTTPD2DQ all use map 0F, opcode E6, with F3, F2 and 66 respectively. They fall through to AVX2 here. GCC's Sandy Bridge encodings were c5 fe e6 c0, c5 ff e6 c0 and c5 fd e6 c0. This handles all three mandatory prefixes. Intel XED encodings.
| if (map == Map0F) { | |
| if (map == Map0F) { | |
| if (opcode == 0xE6 && prefix != 0) return true; |
| case 0x2B: | ||
| case 0x45: case 0x46: case 0x47: |
There was a problem hiding this comment.
The VEX.128 form of VPACKUSDW is AVX. The 256-bit form requires AVX2. Removing 0x2B from the 128-bit list lets Sandy Bridge run the former. The existing VPACKUSDW xmm unit test also needs to expect zero, as in the linked commit. Intel XED register and memory encodings.
| case 0x2B: | |
| case 0x45: case 0x46: case 0x47: | |
| case 0x45: case 0x46: case 0x47: |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: prevent the classifier from treating invalid or incomplete instruction encodings as evidence that the host CPU feature is required.
What I ran
- Inspected the prepared diff for head
e88c95e01607d3a8f2ddb67e175a76f23407cd5band targeted repository source usingrepo_read.py. - No build or tests were run during this review.
Results
| Check | Result | Note |
|---|---|---|
| Source review | failed | Verified classifier defect |
| Build and tests | not run | No commands executed |
Findings
Blocking
core/relinker/codegen/src/x86/HostCpuFeatureClassifier.cpp:154andcore/relinker/codegen/src/x86/HostCpuFeatureClassifier.cpp:156: the legacy fallback classifies TZCNT/LZCNT fromF3 0F BC/BDand MOVBE from0F 38 F0/F1without validating the remaining encoding. Since each scanned instruction is passed with its decoded length, a truncated encoding can be labeled as requiring one of these features. The converter then unions those bits into the output record, and libkernel rejects hosts lacking the recorded feature even if the instruction is not valid code and would not execute. Validate the full instruction encoding before recording a requirement, or make this fallback conservative for incomplete or invalid encodings.
Non-blocking
None.
Not verified
- No tests or build were run. The PR description reports test results, but they were not independently reproduced.
- The changed source files read were
core/libs/prx/libc/src/ApplicationProcessParameters.cpp,core/libs/prx/libkernel/System/src/HostCpu.cpp,core/relinker/codegen/src/x86/HostCpuFeatureClassifier.cpp,core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp,core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp, andcore/relinker/codegen/include/codegen/x86/VexEncoding.hpp. The prepared diff was inspected; other changed files were not read from their full head contents. - Excluded files were not reviewed; the
files.jsonlisting was unavailable through the reader.
To get this to a good state
Validate legacy instruction encodings before including their feature bits in the record, then add or update focused classifier tests and rerun the relevant checks on the new head.
|
Independent check of Among the instructions a Zen 2 title can contain, the only wrong AVX2 requirements are the four that @ocr1n listed: VEX.128 VPACKUSDW ( With PR #23279, opened on Nov 19 and also based on #22530, records the same seven extensions for AI-assisted (Claude). |
e88c95e to
58eb599
Compare
|
Thanks for the sweep. Fixed in On #23279: agreed, it is an older implementation of the same #22530 proposal. I mentioned the overlap in the PR body; the maintainers should pick one rather than merging both. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: correct AVX1/AVX2 classification so the host CPU record does not miss retained instructions that require AVX2.
What I ran
Reviewed head 58eb599f2fe4c40f4a605d30b5a9becc38b0ff9f from the prepared diff and repository files read through repo_read.py. No commands or tests were run in this review; the test results in the PR description are author-reported.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | Reviewed the classifier, conversion flow, record parsing and output layout. |
| Tests in this review | not run | No tests were run. |
| Author-reported tests | not run | Description reports 12/12 selected tests passed. |
Findings
Blocking
core/relinker/codegen/src/x86/HostCpuFeatureClassifier.cpp:16: The AVX1 allowlist treats all VEX.256 forms of several opcode ranges as AVX1 without accounting for mandatory prefix. For example, VEX.256VPINSRW(VEX.66.0F C4) is AVX2, but opcodeC4matches thePrefix66range at lines 24–30 and is classified as AVX1. If this instruction survives lowering, the record omits AVX2 and libkernel can allow startup on a host that cannot execute it. Restrict the allowlist entries to the exact opcode/prefix combinations defined by AVX, and add classifier cases for VEX.256 instructions that require AVX2.
Non-blocking
None.
Not verified
- No tests or build commands were run. The PR description reports Windows 11 tests and byte-level record checks; those were not independently run here.
- Sandy Bridge/Ivy Bridge startup behavior and behavior on a physical console were not verified.
- Read the prepared description, commits, manifest and diff, plus targeted ranges of
ApplicationProcessParameters.cpp,HostCpuFeatureClassifier.cpp,WindowsPePatcher.cpp,HostCpu.cpp,Conversion.cpp,LinuxElfPatcher.cpp, andProgramHeaderLayoutBuilder.cpp. All 27 files listed asreviewedin the manifest were included in the bundle, but the full text of every changed file was not read.files.jsonexclusions were not inspected.
To get this to a good state
Correct the AVX1 opcode/prefix allowlist and add a regression test for a retained AVX2-only VEX.256 form such as VPINSRW; rerun the classifier and conversion tests on the updated head.
19927a3 to
096b707
Compare
|
Fixed in
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The inspected changes show no verified blocking defect; the full changed-file review and programmatic checks were not completed.
What I ran
- Reviewed prepared diff and targeted source at head
096b707771c9491170a619bf6bc082e946383ae6usingrepo_read.py. - No tests or build checks were run.
Results
| Check | Result | Note |
|---|---|---|
| Targeted source review | passed | No blocker verified in inspected code |
| Tests and build | not run | Author-reported results were not independently run |
| Full changed-file review | not run | Several changed files were not read |
Findings
Blocking
None verified in the inspected code.
Non-blocking
- Complete review of the classifier, output patchers, and record parsing would provide stronger confidence in the new cross-platform behavior.
Not verified
- Read:
review/description.md,review/commits.md,review/manifest.json,review/diff.patch; targeted portions ofcore/libs/prx/libc/src/ApplicationProcessParameters.cpp,core/libs/prx/libkernel/System/src/HostCpu.cpp,core/libs/tests/HostCpu.cpp,core/relinker/codegen/src/Amd64OnlyConverter.cpp,core/relinker/codegen/src/x86/HostCpuFeatureClassifier.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,core/relinker/relinker/src/pipeline/Conversion.cpp, andcore/relinker/relinker/tests/test_hostcpu_record.py. - Excluded from direct reading: the remaining changed files listed in
review/manifest.json; the targeted files above were not all read in full.review/files.jsonwas unavailable through the reader. - Host CPU record behavior on physical hardware, supported host operating systems, and the author-reported test runs were not independently confirmed.
To get this to a good state
Nothing is required. Optional: complete review of the remaining changed files and run the relevant checks.
|
@momgaroganuchi-crypto Thanks for the fixes. I re-ran the same iced-x86 sweep on 096b707. The four forms from before are fixed, but the VBROADCAST change introduced a new wrong AVX2 requirement for five AVX1 instructions. In case 0x0C: case 0x0D: case 0x0E: case 0x0F: case 0x17:
case 0x18: case 0x19:
return !registerForm;So 0C to 0F and 17 now fall through to the VBROADCAST rule. Their register forms return false and get AVX2:
The memory forms are still fine. These are all AVX1, and Moving Apart from these five, the sweep finds no other wrong requirement for the instructions a Zen 2 title can contain, and no missed one. The only other AVX2 over-requirement is 256-bit VPCLMULQDQ, which Zen 2 does not have. AI-assisted (Claude). |
Linux and Windows output now carries a 16-byte AnyPS5 record (magic and an eight-byte mask) in a PT_OS_HOSTCPU program header or a .hostcpu PE section. The classifier maps every kept instruction to LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA or F16C, the converter unions the mask for the executable and every bundled module converted in the same run, and libkernel requires the baseline plus the recorded bits, keeping the old all-extensions check when no record is present. This lets --to-avx output start on a host with AVX but without AVX2, so the option no longer requires --macos. A retained extension the lowering does not cover is recorded and refuses start-up instead of raising an illegal instruction later. The classifier is conservative: a 256-bit VEX opcode outside the AVX1 list counts as AVX2, and every byte of an executable segment is decoded. Unit tests cover the classifier, the converter mask and the recorded-mask checks in libkernel; an end-to-end test converts a fixture with --to-avx and validates both output records.
VEX.128 VPACKUSDW is AVX and only its 256-bit form is AVX2; VCVTDQ2PD, VCVTPD2DQ and VCVTTPD2DQ are AVX in their 256-bit forms. Removes 0x2B from the 128-bit AVX2 list, adds 0xE6 to the AVX1 256-bit lists and covers the encodings.
Requires the full legacy instruction length before recording TZCNT, LZCNT or MOVBE, so truncated encodings add no requirement. Classifies register-source VBROADCASTSS and VBROADCASTSD as AVX2 while their memory forms stay AVX1, and covers the forms in the classifier tests.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: fix the missing non-VEX host-feature classifications so --to-avx records every retained extension.
What I ran
- Reviewed head
b76859268c8e0f6da43f50fdc68f09bd3d26c919; base ismain. - No build or tests were run. The description reports selected tests and an encoding sweep; those are author-reported, not runs performed in this review.
- Read
description.md,commits.md,manifest.json, and all 1,749 lines ofdiff.patch. Read changed source inApplicationProcessParameters.cpp,HostCpu.cpp,Amd64OnlyConverter.cpp,HostCpuFeatureClassifier.cpp,LinuxElfPatcher.cpp,WindowsPePatcher.cpp, andConversion.cpp; readfiles.jsonequivalent via the review-folder listing. All changed files were included in the prepared folder. Other changed files were not read in full.
Results
| Check | Result | Note |
|---|---|---|
| Source review | failed | One feature-classification defect |
| Build and tests | not run | No execution environment available |
| Description claims | not run | Only checked against inspected source |
Findings
Blocking
core/relinker/codegen/src/x86/HostCpuFeatureClassifier.cpp:102— The VEX classifier does not record AVX-VNNI, AVX-IFMA, or AVX-VNNI-INT8/AVX-NE-CONVERT instructions. These extensions use VEX encodings, but their opcode forms are not in the BMI/FMA/F16C/AVX2 checks and fall through to0for VEX.128 or AVX1 classification for selected VEX.256 forms. The converter aggregates this mask for retained instructions, and libkernel then uses it to decide which CPU features are required, so a host lacking one of these extensions can pass startup and fault when such an instruction executes. Add bits and runtime CPUID checks for these supported instruction families, or conservatively classify their encodings as requiring an existing unsupported feature that causes startup rejection.
Non-blocking
None.
Not verified
- Did not run the relinker build, unit tests, or end-to-end conversion fixture. The author reports tests on Windows 11 and a classifier sweep; these results were not independently confirmed.
- Did not inspect every changed file's full text or validate behavior on Linux, Windows, macOS, or physical CPUs.
- The description's claim that all retained host extensions are recorded is not supported by the classifier paths inspected.
To get this to a good state
- Correct the classifier/runtime handling for the missing VEX instruction families, add regression coverage, and rerun the classifier and end-to-end record tests on the updated head.
Record AES, PCLMULQDQ, RDRAND, RDSEED, ADX, SHA, CLFLUSHOPT, CLWB, RDPID, XSAVEOPT, XSAVEC, XSAVES, SSE4A, CLZERO, RDTSCP and FSGSBASE in the host CPU record, detect the legacy encodings that carry them in the classifier, and read CPUID leaf 80000001 EDX for RDTSCP. Extend the record, classifier and runtime tests and the debt note.
b768592 to
4afb5db
Compare
|
@MarcZX10 fixed at
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
I did not verify a blocking defect, but the review is incomplete because several changed files were not read.
What I ran
Reviewed head 4afb5db7993a3e0611771fcf45252ff074ac8046. I ran no commands or tests. The author-reported test results in the description were not independently verified.
Results
| Check | Result | Note |
|---|---|---|
| Code review | not run | Review incomplete |
| Tests | not run | Author-reported results only |
| Negative control | not run | Not performed |
Negative control
Could not run a negative control.
Findings
Blocking
None verified in the files read.
Non-blocking
Before treating this as approval, review the remaining changed files; the review did not cover every changed file.
Not verified
Read the prepared description, commits, manifest and diff, plus the full head contents of core/libs/prx/libc/src/ApplicationProcessParameters.cpp, core/libs/prx/libkernel/System/src/HostCpu.cpp, core/relinker/codegen/src/x86/HostCpuFeatureClassifier.cpp, core/relinker/codegen/src/Amd64OnlyConverter.cpp, core/relinker/codegen/src/x86/X64InstructionDecoder.cpp, core/relinker/codegen/tests/HostCpuFeatureClassifierTests.cpp, and portions of core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp, core/relinker/elfpatcher/src/linux/LinuxElfPatcher.cpp, and core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp. Other changed files were not read. No files were excluded from the listing returned by the review reader. The CI results, runtime behavior on a host without AVX2, and physical-console behavior were not verified.
To get this to a good state
Nothing is required. Optional: complete review of the remaining changed files before making a formal approval decision.
|
@momgaroganuchi-crypto the four leaf 7 subleaf 1 families, their record bits and the CPUID reads in One gap is left in the classifier:
A znver2 toolchain emits AES intrinsics in these forms, and a host such as an i3-2100 or i3-3220 has AVX but no AES-NI, so Tests that would cover it: |
ligmaSec
left a comment
There was a problem hiding this comment.
Configured and built the submitted head on Linux with ANYPS5_RELINKER_ONLY=ON. The host_cpu_feature_classifier, cli_args, and amd64_only_converter CTests all passed. The test scope covered classification and relinker argument and converter behavior. It did not exercise the generated CPU requirement record through a native guest launch.
AI-assisted: yes.
What
--to-avxlowers BMI1, BMI2, LZCNT and MOVBE for hosts with AVX but without AVX2, but only--macosoutput could start there:CheckHostCpuin libkernel required LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA and F16C unconditionally and did not know what the conversion removed.The relinker now records what the output still needs:
HostCpuFeatureClassifiermaps one decoded instruction to LZCNT, BMI1, BMI2, MOVBE, AVX2, FMA, F16C, AES, PCLMULQDQ, RDRAND, RDSEED, ADX, SHA, CLFLUSHOPT, CLWB, RDPID, XSAVEOPT, XSAVEC, XSAVES, SSE4A, CLZERO, RDTSCP, FSGSBASE, AVX-VNNI, AVX-IFMA, AVX-VNNI-INT8 or AVX-NE-CONVERT, including the legacy encodings of the last sixteen and the VEX encodings of the AVX-VNNI, AVX-IFMA, AVX-VNNI-INT8 and AVX-NE-CONVERT families. A 256-bit VEX opcode outside the AVX1 list counts as AVX2, a 128-bit VEX opcode counts as AVX2 only for the listed AVX2-only forms, and FMA and F16C are matched before the width rule. The classification is deliberately conservative: data decoded as code can only require more. VEX.128VPACKUSDWand the 256-bitVCVTDQ2PD,VCVTPD2DQandVCVTTPD2DQare AVX1, while only VEX.256VPACKUSDWis AVX2. Register-sourceVBROADCASTSS/VBROADCASTSDare AVX2 while their memory forms are AVX1; the other 0F38/66 AVX1 opcodes (VPERMILPS,VPERMILPD,VTESTPS,VTESTPD,VPTEST,0x0C-0x0Fand0x17) stay AVX1 in both forms. Legacy encodings, including TZCNT, LZCNT, MOVBE and the retained-extension forms, are recorded only after the full encoding passesX64InstructionDecoder; register and memory forms are distinguished so a fence is not mistaken for XSAVEOPT or CLWB.Amd64OnlyConverterclassifies every scanned instruction and unions the extensions of the instructions that no lowering replaced, in the executable and in every bundled module converted in the same run.GuestModuleBuilderreturns that union.Linux writes a 16-byte
PT_OS_HOSTCPUprogram header pointing into the extra block; Windows writes a.hostcpusection next to.procpar. Both contain the magicAPS5HCP1and an eight-byte mask.libc reads the record. libkernel requires the baseline (SSE through SSE4.2, POPCNT, CMPXCHG16B, LAHF/SAHF and AVX) plus the recorded bits, and keeps the existing all-extensions check when no record is present. The error names the missing recorded extensions. The runtime reads CPUID leaf 7 subleaf 1 for AVX-VNNI (EAX bit 4), AVX-IFMA (EAX bit 23), AVX-VNNI-INT8 (EDX bit 4) and AVX-NE-CONVERT (EDX bit 5), and leaf 80000001 EDX for RDTSCP.
--to-avxno longer requires--macos, and the CLI and user documentation describe the record. macOS output is unchanged:CheckHostCpuis not compiled there and no record is written.The record is written only for
--to-avx; other output keeps the old behavior. It is a union rather than per-module records, so a module loaded later from a separate conversion does not add bits. Implements the proposal in #22530. It overlaps the older #23279, which implements the same proposal; the two should be coordinated, not merged both.Tested
Windows 11 26200, WinLibs GCC 16.2.0, AMD Ryzen AI 9 HX PRO 375 (Radeon 890M),
build-full, based onmainf5b7e1d1acafter rebasing:host_cpu,host_cpu_feature_classifier,amd64_only_windows,cli_argsandamd64_only_converterpass.host_cpu_recordhit a local WindowsPermissionErrorreading the converted file, so CI must reconfirm it.iced-x861.22 sweep of every valid VEX.L=1 encoding finds no instruction that this classifier records as AVX1 while iced reports AVX2.New end-to-end
host_cpu_record: converts a fixture with a kept FMA and a loweredVPADDD ymmto Linux and Windows with--to-avx. Both records contain the magic and exactly the FMA and RDSEED bits; a plain conversion contains no record, and the Linux header points into aPT_LOAD.New unit tests cover every classifier family and retained-extension encoding, the converter union and the subtraction of lowered instructions, and
CheckHostCpuwith an empty record, a partial record, each new bit and a baseline failure.python tools/debt_fold.py --checkandpython tools/check_conventions.py --base origin/mainpass.python tools/pr_overlap.py --branch feat/relinker-to-avx-host-cpufinds no open PR implementing these functions; it reports file-level overlap with older relinker PRs (fix(relinker): keep embedded data tables out of --to-intel and --to-rosetta conversion #11525, feat(relinker): add opt-in PEXT and PDEP lowering for Rosetta #12678, fix(relinker): resolve a needed module on the executable that exports its imports #15245, fix(relinker): preserve jump tables formed by 32-bit LEA #19569, fix(relinker): analyze referenced code beyond SCE scan boundaries #10861) that touch the same conversion files for unrelated reasons.Not tested on a Sandy Bridge or Ivy Bridge host: no such hardware was available. The record was validated as bytes in the output and through the unit tests, not by starting a title on a CPU without AVX2. No decrypted title binary was available here, so the record was not produced from a retail title; the fixture covers FMA, AVX2 and RDSEED.
Checklist
Based on current
main; no other open PR implements the same functionsOne topic per PR; follow-ups go in a new PR
No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
Unimplemented paths throw (
NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt fileNo notes, investigation
.mdfiles or images added to the repository (attach them to this PR)New third-party code is a submodule built from source
Generic behaviour, not specific to one title
Depends on: none
Fixes: relinker, libkernel: let
--to-avxoutput run on Linux and Windows by recording the CPU features it still needs #22530Unblocks: none
GPUs tested: n/a
AI-assisted: yes