fix(relinker): keep Windows images without relocations loadable #1958

Merged
arcwiser merged 1 commit from upstream-pr/1958 into main 2026-10-10 06:06:21 +00:00
arcwiser commented 2026-10-09 02:28:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by arcwiser on 2026-10-09T02:28:13Z.


What

Stop setting IMAGE_FILE_RELOCS_STRIPPED on Windows PE outputs whose base-relocation directory is empty.

This is the ordinary path for Windows guest modules with no absolute addresses to relocate, including output from both WindowsGuestModuleWriter and WindowsPePatcher. Marking those images as relocation-stripped unnecessarily makes them non-relocatable and causes CreateProcess to reject them with error 623 on the reporter's Windows configuration. The fixed image base and existing DYNAMIC_BASE behavior remain unchanged.

Add a Windows PE builder regression assertion for the emitted COFF characteristics.

Closes #1955 in part. The remaining windows_address_space failure is a separate stack-placement assumption and does not prevent generated images from starting.

Tested

  • Rebased onto current main (0c0dc1e9)
  • Windows 11 NT 10.0.26200.0, WinLibs GCC 15.2.0, Ninja, Release relinker-only build: passed
  • windows_dependency_diagnostics: passed
  • amd64_only_windows: passed, including the new COFF characteristics assertion
  • guest_needed_modules: passed
  • guest_module_directories: passed
  • windows_import_modules: passed
  • Full current relinker CTest suite: 42/46 passed. The known windows_address_space high-stack assertion remains; three unrelated current-main tool tests fail locally because Python 3.10 lacks subprocess._text_encoding and the sandbox blocks their temporary Git/file-replacement operations
  • python tools/check_conventions.py --base origin/main: passed
  • git diff --check origin/main HEAD: passed
  • test-registration check: 8 executables, none missing
  • project overlap checker: no overlap with open pull requests
  • Upstream manual Build run on the previous head passed the Windows, Linux, macOS, and relinker jobs; this rebased head requires a fresh maintainer-triggered run

Checklist

  • Based on current main; no other open PR implements the same change
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths still throw
  • No investigation files or images added
  • No third-party code added
  • Generic behaviour, not title-specific
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4795184795 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1958). Originally posted by [arcwiser](https://github.com/arcwiser) on 2026-10-09T02:28:13Z. --- ### What Stop setting `IMAGE_FILE_RELOCS_STRIPPED` on Windows PE outputs whose base-relocation directory is empty. This is the ordinary path for Windows guest modules with no absolute addresses to relocate, including output from both `WindowsGuestModuleWriter` and `WindowsPePatcher`. Marking those images as relocation-stripped unnecessarily makes them non-relocatable and causes `CreateProcess` to reject them with error 623 on the reporter's Windows configuration. The fixed image base and existing `DYNAMIC_BASE` behavior remain unchanged. Add a Windows PE builder regression assertion for the emitted COFF characteristics. Closes #1955 in part. The remaining `windows_address_space` failure is a separate stack-placement assumption and does not prevent generated images from starting. ### Tested - Rebased onto current `main` (`0c0dc1e9`) - Windows 11 NT 10.0.26200.0, WinLibs GCC 15.2.0, Ninja, Release relinker-only build: passed - `windows_dependency_diagnostics`: passed - `amd64_only_windows`: passed, including the new COFF characteristics assertion - `guest_needed_modules`: passed - `guest_module_directories`: passed - `windows_import_modules`: passed - Full current relinker CTest suite: 42/46 passed. The known `windows_address_space` high-stack assertion remains; three unrelated current-main tool tests fail locally because Python 3.10 lacks `subprocess._text_encoding` and the sandbox blocks their temporary Git/file-replacement operations - `python tools/check_conventions.py --base origin/main`: passed - `git diff --check origin/main HEAD`: passed - test-registration check: 8 executables, none missing - project overlap checker: no overlap with open pull requests - Upstream manual Build run on the previous head passed the Windows, Linux, macOS, and relinker jobs; this rebased head requires a fresh maintainer-triggered run ### Checklist - [x] Based on current `main`; no other open PR implements the same change - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths still throw - [x] No investigation files or images added - [x] No third-party code added - [x] Generic behaviour, not title-specific - [x] Depends on: none - [x] AI-assisted: yes
MarcZX10 commented 2026-10-09 02:31:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T02:31:29Z.

Review: APPROVED


Reviewed the complete two-file diff and the Windows reproduction in #1955. Clearing IMAGE_FILE_RELOCS_STRIPPED while keeping the fixed base and DYNAMIC_BASE behavior unchanged matches the controlled Windows result; the test asserts the emitted COFF characteristics. This head is based directly on current main. On Linux/GCC 12.2, the relinker-only build and all 38 CTests passed, including Windows PE generation/integration checks that run portably; Conventions and diff whitespace checks passed. The author reports the Windows-only builder test and four affected Windows integration tests passing on 26200; windows_address_space remains a separate stack-placement failure on that build. GitHub reports no upstream checks for this head, so this approval records local Linux validation plus the author-provided Windows evidence.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5465068333 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1958#pullrequestreview-5465068333). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T02:31:29Z. **Review:** APPROVED --- Reviewed the complete two-file diff and the Windows reproduction in #1955. Clearing IMAGE_FILE_RELOCS_STRIPPED while keeping the fixed base and DYNAMIC_BASE behavior unchanged matches the controlled Windows result; the test asserts the emitted COFF characteristics. This head is based directly on current main. On Linux/GCC 12.2, the relinker-only build and all 38 CTests passed, including Windows PE generation/integration checks that run portably; Conventions and diff whitespace checks passed. The author reports the Windows-only builder test and four affected Windows integration tests passing on 26200; windows_address_space remains a separate stack-placement failure on that build. GitHub reports no upstream checks for this head, so this approval records local Linux validation plus the author-provided Windows evidence.
Dextroid17 commented 2026-10-09 03:06:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T03:06:32Z.

Review: COMMENTED


What I could and could not check on Linux — including a correction worth writing down for the next verifier.

  • The header edit is right: the word at peOffset + 22 is the COFF Characteristics; 0x22 is IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LARGE_ADDRESS_AWARE, and the old 0x23 added IMAGE_FILE_RELOCS_STRIPPED. So this drops exactly the flag the body says CreateProcess rejects with error 623 and nothing else.
  • The new test cannot run here: it lives in Amd64OnlyWindowsTests.cpp, whose target amd64_only_windows_tests is defined inside the platform guard that closes at core/relinker/CMakeLists.txt:124, so on Linux there is neither a target nor a ctest entry for it.
  • Note for the next Linux verifier: ctest -R amd64_only_converter is a different target whose binary does not contain this file at all. I ran that first and the new assertion looked like it did not bite. It does — the test's directories array is all-zero (Amd64OnlyWindowsTests.cpp:616-617), which is exactly the directories[5].Size == 0 case the old code wrote 0x23 for.
  • What did run here: windows_dependency_diagnostics, the other Linux-runnable test that includes WindowsPeWriter, passes with this change — no regression on the Linux/Mesa side of the writer.
  • One sentence worth adding to the body: the empty-relocation-directory path is not only "fixed-base outputs". WindowsGuestModuleWriter.cpp:82 and WindowsPePatcher.cpp:54 both hand the writer an all-zero directories array, so this is the ordinary path for a Windows guest module that has no relocations.

Not verified: the Windows witness itself (error 623 on NT 10.0.26200.0) — there is no Windows here.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5465259929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1958#pullrequestreview-5465259929). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-09T03:06:32Z. **Review:** COMMENTED --- What I could and could not check on Linux — including a correction worth writing down for the next verifier. - **The header edit is right**: the word at `peOffset + 22` is the COFF `Characteristics`; `0x22` is `IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_LARGE_ADDRESS_AWARE`, and the old `0x23` added `IMAGE_FILE_RELOCS_STRIPPED`. So this drops exactly the flag the body says `CreateProcess` rejects with error 623 and nothing else. - **The new test cannot run here**: it lives in `Amd64OnlyWindowsTests.cpp`, whose target `amd64_only_windows_tests` is defined inside the platform guard that closes at `core/relinker/CMakeLists.txt:124`, so on Linux there is neither a target nor a ctest entry for it. - **Note for the next Linux verifier**: `ctest -R amd64_only_converter` is a *different* target whose binary does not contain this file at all. I ran that first and the new assertion looked like it did not bite. It does — the test's `directories` array is all-zero (`Amd64OnlyWindowsTests.cpp:616-617`), which is exactly the `directories[5].Size == 0` case the old code wrote `0x23` for. - **What did run here**: `windows_dependency_diagnostics`, the other Linux-runnable test that includes `WindowsPeWriter`, passes with this change — no regression on the Linux/Mesa side of the writer. - **One sentence worth adding to the body**: the empty-relocation-directory path is not only "fixed-base outputs". `WindowsGuestModuleWriter.cpp:82` and `WindowsPePatcher.cpp:54` both hand the writer an all-zero `directories` array, so this is the ordinary path for a Windows guest module that has no relocations. Not verified: the Windows witness itself (error 623 on NT 10.0.26200.0) — there is no Windows here. Written with AI assistance.
MarcZX10 commented 2026-10-09 08:39:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T08:39:29Z.


One actionable check remains: the current Conventions run failed because the description uses Summary / Verification / Why, while the repository check requires non-empty What, Tested, and Checklist sections. Please keep the existing technical explanation but move it into those template headings and fill the checklist, including Depends on: none and AI assistance. Also consider the reviewer’s note that a zero relocation directory is the ordinary Windows guest-module path; the current wording “fixed-base PE outputs” may understate the scope. The code review and Linux/Windows evidence remain favorable.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077483491 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1958#issuecomment-6077483491). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T08:39:29Z. --- One actionable check remains: the current Conventions run failed because the description uses `Summary` / `Verification` / `Why`, while the repository check requires non-empty `What`, `Tested`, and `Checklist` sections. Please keep the existing technical explanation but move it into those template headings and fill the checklist, including `Depends on: none` and AI assistance. Also consider the reviewer’s note that a zero relocation directory is the ordinary Windows guest-module path; the current wording “fixed-base PE outputs” may understate the scope. The code review and Linux/Windows evidence remain favorable.
MarcZX10 commented 2026-10-09 08:40:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T08:40:30Z.


One more contribution-rule follow-up: this head is still based on f1451396, while current upstream main is 6cc0503d. Please rebase and rerun the current-head checks along with the template correction; the already-passing Build evidence remains useful for the current source diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077498323 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1958#issuecomment-6077498323). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T08:40:30Z. --- One more contribution-rule follow-up: this head is still based on `f1451396`, while current upstream `main` is `6cc0503d`. Please rebase and rerun the current-head checks along with the template correction; the already-passing Build evidence remains useful for the current source diff.
adriadam10 commented 2026-10-10 06:06:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:06:18Z.


Checked the one-line change: the COFF Characteristics word at peOffset + 22 goes from 0x23 to 0x22, dropping only IMAGE_FILE_RELOCS_STRIPPED. Both writers pass an all-zero directory array only when there are no relocations, so there are no absolute addresses to fix up and the image can be rebased safely. The new assertion at Amd64OnlyWindowsTests.cpp:619 reads the right offset (0x80 + 22). Relinker build and ctest (47/47) pass on Linux; the Windows-only amd64_only_windows_tests target can't run here, so that part and the error 623 itself rest on your controlled runs and the Windows results in the thread. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094490101 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1958#issuecomment-6094490101). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:06:18Z. --- Checked the one-line change: the COFF `Characteristics` word at `peOffset + 22` goes from `0x23` to `0x22`, dropping only `IMAGE_FILE_RELOCS_STRIPPED`. Both writers pass an all-zero directory array only when there are no relocations, so there are no absolute addresses to fix up and the image can be rebased safely. The new assertion at `Amd64OnlyWindowsTests.cpp:619` reads the right offset (`0x80 + 22`). Relinker build and ctest (47/47) pass on Linux; the Windows-only `amd64_only_windows_tests` target can't run here, so that part and the error 623 itself rest on your controlled runs and the Windows results in the thread. Merging.
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!1958
No description provided.