OLD-8847: restore old upstream PR 8847 - pe_loader: move an image with no relocation directory; refuse only on IMAGE_FILE_RELOCS_STRIPPED #634

Manually merged
github merged 3 commits from gh-pr/634/head into gh-pr/634/base 2026-11-26 09:12:56 +00:00
Owner

@⁠aslan2142 on GitHub · 2026-11-24 10:33 UTC · original
aslan2142:loader-rebase-without-reloc-dir → main · +113 −10 · 4 files · 3 commits · merged 2026-11-25 22:53 UTC

Claimed in the coordination issue as: OLD-8847 #14

Restoration of my original pull request, old upstream PR 8847 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Its two commits are cherry-picked onto main at 21625bca8 without conflicts. One extra commit replaces the links to the old PR number, which no longer resolve, with plain text.

What and why

Loader::map_image refuses any image whose preferred base is taken when the image has no relocation directory (runtime/src/pe_loader.cpp:1428-1431 and :1456-1459 on main). Windows only refuses that move when IMAGE_FILE_RELOCS_STRIPPED is set. With the flag clear, it moves the image without fix-ups.

This PR follows Windows:

Image Base taken, main Base taken, this PR
flag clear, no relocation directory refused moved, not fixed up, one log line
flag set, no relocation directory refused refused, and the message names the flag
has a relocation table moved and fixed up moved and fixed up, whatever RELOCS_STRIPPED says (the Windows 11 measurement from the original PR's review)
  • An image whose base is free maps at its base, as on main.
  • The retail executable and the package's DLLs are unaffected: all of them have a relocation table and the flag clear, as measured on the original PR.

Tested

  • On Linux under Wine 11.22, built with clang for the mingw target. MSVC is left to CI.
  • main (21625bca8) with only this PR's tests: 99 checks, 2 failed. The two are "an image without relocations, flag clear, moves when its base is taken" and "an image with IMAGE_FILE_RELOCS_STRIPPED is refused when its base is taken".
  • This branch: 99 checks, 0 failed.
  • Other checks: git diff --check and python -I scripts/check_no_game_data.py on the changed files are clean.
  • No game data: synthetic PE images only; no game files were used and no retail code was run.

GPUs tested: n/a (CPU-only loader tests)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 10:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/634) `aslan2142:loader-rebase-without-reloc-dir` → `main` · +113 −10 · 4 files · 3 commits · merged 2026-11-25 22:53 UTC Claimed in the coordination issue as: OLD-8847 https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 Restoration of my original pull request, old upstream PR 8847 in `ItsNotRexed/Leonida`, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Its two commits are cherry-picked onto `main` at `21625bca8` without conflicts. One extra commit replaces the links to the old PR number, which no longer resolve, with plain text. ### What and why `Loader::map_image` refuses any image whose preferred base is taken when the image has no relocation directory (`runtime/src/pe_loader.cpp:1428-1431` and `:1456-1459` on `main`). Windows only refuses that move when `IMAGE_FILE_RELOCS_STRIPPED` is set. With the flag clear, it moves the image without fix-ups. This PR follows Windows: | Image | Base taken, `main` | Base taken, this PR | |---|---|---| | flag clear, no relocation directory | refused | moved, not fixed up, one log line | | flag set, no relocation directory | refused | refused, and the message names the flag | | has a relocation table | moved and fixed up | moved and fixed up, whatever `RELOCS_STRIPPED` says (the Windows 11 measurement from the original PR's review) | - An image whose base is free maps at its base, as on `main`. - **The retail executable and the package's DLLs are unaffected:** all of them have a relocation table and the flag clear, as measured on the original PR. ### Tested - **On Linux under Wine 11.22,** built with clang for the mingw target. MSVC is left to CI. - **`main` (`21625bca8`) with only this PR's tests:** 99 checks, 2 failed. The two are "an image without relocations, flag clear, moves when its base is taken" and "an image with IMAGE_FILE_RELOCS_STRIPPED is refused when its base is taken". - **This branch:** 99 checks, 0 failed. - **Other checks:** `git diff --check` and `python -I scripts/check_no_game_data.py` on the changed files are clean. - **No game data:** synthetic PE images only; no game files were used and no retail code was run. GPUs tested: n/a (CPU-only loader tests) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) AI-assisted (Claude Code, Claude Opus 5.5).
The loader refused any image whose preferred base was taken when it had no relocation directory. Windows'
loader decides on the file header flag instead (LdrRelocateImage, the same in Wine's perform_relocations and
ReactOS's LdrRelocateImageWithBias): IMAGE_FILE_RELOCS_STRIPPED set means the image cannot move and is
refused (STATUS_CONFLICTING_ADDRESSES); with the flag clear and an empty directory the image is moved with
nothing to fix up, as a second copy of such a DLL is.

map_image now does the same, for an EXE and a DLL alike: it refuses to move a flag-set image (also one that
has a relocation table, as Windows does), moves a flag-clear image without a directory and logs one
"[rt] loader: ... moved ... with no relocations" line, so a move without fix-ups shows in traces.
base_reservation::needed keeps reserving the main image's range for both kinds of image without
relocations, and now also for a flag-set image with a table, so the main image keeps its base wherever it
did before. The retail executable and every package DLL have a relocation table and the flag clear, so
neither path applies to them.

loader_test covers a flag-clear image moved when its base is held (it loads elsewhere, nothing is fixed
up, its DllMain runs), the same image with the flag set (refused), the flag at a free base (maps), and the
flag with a relocation table (refused). test_failed_dependency_not_registered's dependency shared its
parent's base and was refused for that; it now fails on its corrupt import table, which is what the test
describes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Zombins2 measured the Windows 11 (26200) loader with synthetic x64 DLLs in #8847. An image with
IMAGE_FILE_RELOCS_STRIPPED set and a relocation table was moved and fixed up when its base was taken. The
previous commit refused that case, while main relocated it. That is now back to main's behaviour: a moved
image with a table is fixed up whatever the flag says, and the flag refuses a move only when there is no
table. base_reservation::needed is back to main's test (the directory size) and no longer reserves for a
flag-set image with a table.

The core change stays: with the flag clear and no relocation directory, the image is moved with nothing
fixed up and the move is logged. That matches the measurement.

Windows also refused flag-set DLLs without a relocation directory at a free base (error 487), and it is not
known why. The loader keeps main's behaviour there and maps them at their base. runtime/README.md records
this as an open question, and loader_test's check for it no longer claims Windows parity. The flag-with-table
check now expects a move with the DIR64 fix-up applied.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Windows 11 measurement behind this behaviour was posted in a review of pull request 8847 of the original
repository, which went private on 2026-11-23, so its link and the "#8847" references in pe_loader.cpp and
loader_test.cpp lead nowhere now. runtime/README.md keeps the measurement and the open question in its own
words and names where it came from; the code comments point at the README. No behaviour changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:12:54 +00:00
github manually merged commit bb256ebbf3 into gh-pr/634/base 2026-11-26 09:12:56 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 01:39 UTC · original

Reviewed bb256ebb: read the relocation-move policy end to end (a relocation table applies regardless of IMAGE_FILE_RELOCS_STRIPPED; with no table, flag set refuses and flag clear moves without fixups and logs) and all three commits. The only 8847 reference in docs/code is runtime/README.md's unreadable-origin note, matching the old-number rule, and the Win11 error-487 free-base question stays documented. Merges cleanly into current origin/main (auto-merging disjoint edits in runtime/src/pe_loader.cpp and runtime/README.md). On arm64 Linux (no network), the portable runtime builds and its CTest passes on bb256ebb (72/72, 2 skipped: shader_library_corpus, vk_sync_validation); loader_test is WIN32-only (windows.h) and was not run; compileall, the 12 doc tests (47 tests, 2 git-dependent skipped), test_boot_trace.py, test_ctest_registration.py, and check_no_game_data.py all pass on pr634, origin/main, and the merged tree. Statically against origin/main, all helpers in test_moved_without_relocations exist, Block 1 (flag clear) expects a load main refuses, and Block 2 (flag set) asserts the new "stripped" refusal message, so the test exercises the change. No blocking findings. AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 01:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/634#issuecomment-7149803076) Reviewed bb256ebb: read the relocation-move policy end to end (a relocation table applies regardless of `IMAGE_FILE_RELOCS_STRIPPED`; with no table, flag set refuses and flag clear moves without fixups and logs) and all three commits. The only `8847` reference in docs/code is `runtime/README.md`'s unreadable-origin note, matching the old-number rule, and the Win11 error-487 free-base question stays documented. Merges cleanly into current `origin/main` (auto-merging disjoint edits in `runtime/src/pe_loader.cpp` and `runtime/README.md`). On arm64 Linux (no network), the portable runtime builds and its CTest passes on bb256ebb (72/72, 2 skipped: `shader_library_corpus`, `vk_sync_validation`); `loader_test` is WIN32-only (`windows.h`) and was not run; `compileall`, the 12 doc tests (47 tests, 2 git-dependent skipped), `test_boot_trace.py`, `test_ctest_registration.py`, and `check_no_game_data.py` all pass on `pr634`, `origin/main`, and the merged tree. Statically against `origin/main`, all helpers in `test_moved_without_relocations` exist, Block 1 (flag clear) expects a load main refuses, and Block 2 (flag set) asserts the new `"stripped"` refusal message, so the test exercises the change. No blocking findings. AI-assisted review. **Recommendation:** Merge
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 22:53 UTC · original

Merged: pe_loader moves an image that has no relocation directory, and refuses only on IMAGE_FILE_RELOCS_STRIPPED.

  • Changed since review: nothing. It merges cleanly with main and with #643, and no review point is open.
  • Tested: the full Windows suite under Wine on main 5fab93967 with all nine of these runtime PRs merged together (#634, #643, #684, #657, #677, #638, #710, #688, #671), on llvmpipe and the gfx1036 iGPU (RADV): no test went from pass to fail. loader passes on both.
  • Checked on main 5fab93967 + bb256ebbf: it merges cleanly; the semantic suite passes (493 files, 6,318 tests, 0 files failed); the 15 docs and writer tests pass; check_no_game_data.py is clean on the 4 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 22:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/634#issuecomment-7176906006) Merged: `pe_loader` moves an image that has no relocation directory, and refuses only on `IMAGE_FILE_RELOCS_STRIPPED`. - **Changed since review:** nothing. It merges cleanly with `main` and with #643, and no review point is open. - **Tested:** the full Windows suite under Wine on `main` `5fab93967` with all nine of these runtime PRs merged together (#634, #643, #684, #657, #677, #638, #710, #688, #671), on llvmpipe and the gfx1036 iGPU (RADV): no test went from pass to fail. `loader` passes on both. - **Checked on `main` `5fab93967` + `bb256ebbf`:** it merges cleanly; the semantic suite passes (493 files, 6,318 tests, 0 files failed); the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 4 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.