Skip to content

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

Merged
aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
aslan2142:loader-rebase-without-reloc-dir
Nov 25, 2026
Merged

aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
aslan2142:loader-rebase-without-reloc-dir

Conversation

@aslan2142

@aslan2142 aslan2142 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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

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 and others added 3 commits November 24, 2026 04:58
… IMAGE_FILE_RELOCS_STRIPPED

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 <noreply@anthropic.com>
…s (Windows 11 measurement)

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 <noreply@anthropic.com>
… number

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 <noreply@anthropic.com>
@aslan2142 aslan2142 changed the title OLD-8847: restore ItsNotRexed/Leonida#8847 - pe_loader: move an image with no relocation directory; refuse only on IMAGE_FILE_RELOCS_STRIPPED OLD-8847: restore old upstream PR 8847 - pe_loader: move an image with no relocation directory; refuse only on IMAGE_FILE_RELOCS_STRIPPED Nov 24, 2026
@PierreEbele

Copy link
Copy Markdown
Contributor

Reviewed bb256eb: 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 bb256eb (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

@aslan2142
aslan2142 merged commit 21d3662 into ProjectLeonida:main Nov 25, 2026
8 of 13 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator Author

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

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

aslan2142 added a commit to aslan2142/leonida that referenced this pull request Nov 25, 2026
ProjectLeonida#634 rewrote the same runtime/README.md paragraph on the loader. Its text
stays, and its relocation sentence takes this PR's wording: DIR64 and
HIGHLOW relocations, the other types rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants