Repository navigation
pe_loader: move an image with no relocation directory; the flag refuses only a move without a table - #8847
pe_loader: move an image with no relocation directory; the flag refuses only a move without a table#8847aslan2142 wants to merge 2 commits into
Conversation
… 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>
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Verified on Windows 11.
- Aligns \pe_loader.cpp\ and \�ase_reservation.h\ with official Windows loader (\LdrRelocateImage) semantics:
- An image whose preferred base is already committed is refused only when \IMAGE_FILE_RELOCS_STRIPPED\ is set.
- If the stripped flag is clear and the base relocation directory is absent, the loader relocates the image without fixups (assuming position-independent code) and logs the move cleanly.
- \�ase_reservation::needed\ properly preserves the preferred range reservation for both classes of images without relocations.
- Comprehensive unit tests in
untime/test/loader_test.cpp\ (\ est_moved_without_relocations) cover all 4 permutations (flag clear moved, flag set refused, free base mapped, flag set with reloc directory refused). - Clean-room check and \git diff --check\ pass.
LGTM!
|
Verified head
AI-assisted. |
|
AI-assisted. No game files used. I measured the Windows loader on Windows 11 build 26200 with synthetic x64 DLLs. The core case agrees with this PR: flag clear, no relocation directory, preferred base taken -> moved without fix-ups. Two other cases differ from the PR's new checks on this build. Method:
Two DLLs linked with Here 487 is Win32 Compared with this PR's new
These are DLL loads through Alongside smowlyy's native MSVC result, I also checked head
I can share the probe. |
…s (Windows 11 measurement) Zombins2 measured the Windows 11 (26200) loader with synthetic x64 DLLs in ItsNotRexed#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>
|
Thanks @Zombins2. A measurement of the real loader is exactly what this needed, and it caught a regression I had introduced. Updated in b985d13:
Retested under Wine 11.22 (clang for mingw, not MSVC):
AI-assisted (Claude Code, Claude Opus 5.5). |
|
Checked head
No defect. No game data. AI-assisted (Claude Code). |
sds-228
left a comment
There was a problem hiding this comment.
Re-reviewed at the current head after the relocation-table correction: a present relocation directory is now applied regardless of the strip flag, a strip-flagged image without a table is refused when moved, and an unfixed move is logged. The added loader cases cover those paths plus the unchanged free-base behavior, and the updated documentation records the remaining open question. Diff review only (no local C++ toolchain); no whitespace or game-data issues in the changed files.
AI-assisted (OpenCode).
|
Tested b985d13 (merged onto main 867d922) on RTX 5070, NVIDIA 621.24, Windows 11 (build 26200), Vulkan validation layer on (
Ran the tests that belong to the test files this PR changes (ctest entries, or the test program directly when it is not registered), with no game files ( |
|
Tested
AI-assisted: Codex GPT-6.2 Sol ran the checks, Claude Opus 5.5 reviewed the report. The retail executable (SHA-256 |
Claimed in the coordination issue: #8683 (comment) (Maraco91's finding: #8683 (comment)).
Depends on: none.
What and why
Loader::map_imagerefused any image whose preferred base was taken when it had no relocation directory (runtime/src/pe_loader.cpp, the twothrows at the old lines 1304-1306 and 1334). Windows moves such an image whenIMAGE_FILE_RELOCS_STRIPPEDis clear.Windows reference. Zombins2 measured the Windows 11 (26200) loader in this PR (comment): synthetic x64 DLLs, 84
LoadLibraryExWloads in fresh processes, with the preferred range either held or checked free. Those results are the reference for the cases below; the earlier Wine/ReactOS source reading got the flag-with-table case wrong.Behaviour when the preferred base is taken:
main[rt] loader: <name>: preferred base <addr> is taken, moved to <addr> with no relocations, so a move without fix-ups shows in traces./FIXEDDLLs included), and why is not known. The loader keepsmain's behaviour and maps them at their base.runtime/README.md's loader paragraph records the question, credited to the measurement.base_reservation::needed(the finding's caveat): unchanged frommain. It still reserves the main image's range whenever the image has no relocation directory, flag set or clear. A main image without relocations therefore keeps its base wherever it did before. It is moved without fix-ups only where even the relaunch could not reserve the range, and the relaunch already fails then. Only its comment changed.map_imagetreats both alike. The measurement covers DLLs only. An EXE linked without relocations normally has the flag set (the PE spec: the linker strips relocations from EXEs by default), so it is still refused.loader_test:test_failed_dependency_not_registeredgave its dependency the same base as its parent, so onmainthe dependency was refused for the base clash. It now fails on its corrupt import table, which is what the test describes. It passes both ways.Tested
Local only: Linux, clang 23.1.5 targeting
x86_64-w64-mingw32(lld, static libstdc++), run under Wine 11.22 (Staging). Not MSVC; Zombins2 and smowlyy ran the first commit with MSVC (see the comments). No GPU used.loader_test,test_moved_without_relocations, with the preferred base held unless noted:relocatedis set, the section matches the file byte for byte (nothing fixed up), and its DllMain stub runs at the new address;main's behaviour; see the open question);main'spe_loader.cppwith these tests: 92 checks, 2 failed (the first two cases above).mainpasses 88 of 88.pe_loader.cpp(module_names_test,pe_loader_testwith mingw-builttiny_dll/tiny_exe,test_pe_loader_bounds,startup_trace_test,unimplemented_policy_test): the same results onmainand on the branch.test_pe_loader_boundspasses 54/54 andunimplemented_policy_test87/87.OutputDebugStringcapture).gta6rt --dry-runof the retail executable under Wine, in a sandbox with no network and the game files read-only,mainagainst the branch head:cmake -S runtime -B <build>configures; the loader is not in it, so there is nothing to run there.Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator change.)AI-assisted (Claude Code, Claude Opus 5.5).