upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 05:00:08 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 05:00:08 -0500
commitbb256ebbf32d7493e3d867923ec737e60d3f9f9d (patch)
tree8a20210e80cb4b0f0736bcd750c2c9753b48b219 /runtime
parentca56a0d5eff2f6217a593babcfaff87d46daa15d (diff)
pe_loader: the relocation-move notes stop citing the old pull request 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>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/README.md9
-rw-r--r--runtime/src/pe_loader.cpp2
-rw-r--r--runtime/test/loader_test.cpp10
3 files changed, 10 insertions, 11 deletions
diff --git a/runtime/README.md b/runtime/README.md
index abe3e841b..268ceb45f 100644
--- a/runtime/README.md
+++ b/runtime/README.md
@@ -135,12 +135,11 @@ with the seed on stderr; a seed of 0 uses a fixed non-zero state. Unset, the hos
135`src/pe_loader.cpp` maps x86-64 images at their preferred base, or elsewhere (with relocations) when 135`src/pe_loader.cpp` maps x86-64 images at their preferred base, or elsewhere (with relocations) when
136that base is taken. An image with a relocation table is moved and fixed up whatever `IMAGE_FILE_RELOCS_STRIPPED` 136that base is taken. An image with a relocation table is moved and fixed up whatever `IMAGE_FILE_RELOCS_STRIPPED`
137says; without one, the flag refuses the move, and an image with the flag clear is moved with nothing fixed up (the 137says; without one, the flag refuses the move, and an image with the flag clear is moved with nothing fixed up (the
138loader logs that). The Windows 11 loader does the same in these three cases, as measured by Zombins2 with 138loader logs that). The Windows 11 (build 26200) loader does the same in these three cases, as Zombins2 measured
139synthetic DLLs ([#8847](https://github.com/ItsNotRexed/Leonida/pull/8847#issuecomment-7112587898)). Open 139with synthetic DLLs in a review of old pull request 8847 of the original repository, which is no longer readable.
140question from the same measurement: Windows also refused flag-set DLLs without a relocation directory at a free 140Open question from the same measurement: Windows also refused flag-set DLLs without a relocation directory at a free
141preferred base (error 487, linker-built `/FIXED` DLLs included), and why is not known; the loader still maps those 141preferred base (error 487, linker-built `/FIXED` DLLs included), and why is not known; the loader still maps those
142at their base, as before. It copies headers and 142at their base, as before. It copies headers and sections, applies `IMAGE_REL_BASED_DIR64` relocations, binds
143sections, applies `IMAGE_REL_BASED_DIR64` relocations, binds
144imports by name or ordinal, parses the export table, sets section protections, and registers the 143imports by name or ordinal, parses the export table, sets section protections, and registers the
145image's x64 unwind table (`.pdata`) with `RtlAddFunctionTable`, so exceptions raised in or passing 144image's x64 unwind table (`.pdata`) with `RtlAddFunctionTable`, so exceptions raised in or passing
146through a mapped image are dispatched and stack walks can step over its frames. The table is validated 145through a mapped image are dispatched and stack walks can step over its frames. The table is validated
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index 1c6b91b54..de42996f5 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -1452,7 +1452,7 @@ Module& Loader::map_image(const std::filesystem::path& path, const std::string&
1452 int64_t delta = reinterpret_cast<int64_t>(m->base) - static_cast<int64_t>(oh.ImageBase); 1452 int64_t delta = reinterpret_cast<int64_t>(m->base) - static_cast<int64_t>(oh.ImageBase);
1453 // A moved image with a relocation table is fixed up, whatever IMAGE_FILE_RELOCS_STRIPPED says. Without a table, 1453 // A moved image with a relocation table is fixed up, whatever IMAGE_FILE_RELOCS_STRIPPED says. Without a table,
1454 // the flag refuses the move; with the flag clear the image is moved and nothing is fixed up, so it is trusted to 1454 // the flag refuses the move; with the flag clear the image is moved and nothing is fixed up, so it is trusted to
1455 // hold no absolute addresses. The Windows 11 loader does all three (measured in #8847); that move is logged so 1455 // hold no absolute addresses. The Windows 11 loader does all three (runtime/README.md); that move is logged so
1456 // it shows in traces. base_reservation::needed still keeps the main image's range free when it has no 1456 // it shows in traces. base_reservation::needed still keeps the main image's range free when it has no
1457 // relocation directory, so a main image is moved this way only where the range could not be had. 1457 // relocation directory, so a main image is moved this way only where the range could not be had.
1458 const auto dir = directory(nt, IMAGE_DIRECTORY_ENTRY_BASERELOC); 1458 const auto dir = directory(nt, IMAGE_DIRECTORY_ENTRY_BASERELOC);
diff --git a/runtime/test/loader_test.cpp b/runtime/test/loader_test.cpp
index 926becd12..6930878a9 100644
--- a/runtime/test/loader_test.cpp
+++ b/runtime/test/loader_test.cpp
@@ -655,10 +655,10 @@ void test_initialise_rejects() {
655} 655}
656 656
657// IMAGE_FILE_RELOCS_STRIPPED against a relocation directory, when the preferred base is taken. Measured on the 657// IMAGE_FILE_RELOCS_STRIPPED against a relocation directory, when the preferred base is taken. Measured on the
658// Windows 11 (26200) loader with synthetic DLLs (#8847): with no relocation directory the flag refuses the move and 658// Windows 11 (26200) loader with synthetic DLLs (runtime/README.md): with no relocation directory the flag refuses
659// an image with the flag clear is moved with nothing fixed up; with a relocation table the image is moved and fixed 659// the move and an image with the flag clear is moved with nothing fixed up; with a relocation table the image is
660// up whatever the flag says. The DllMain stub stores through an absolute address in this process, not in the image, 660// moved and fixed up whatever the flag says. The DllMain stub stores through an absolute address in this process,
661// so it runs correctly wherever the image lands. 661// not in the image, so it runs correctly wherever the image lands.
662void test_moved_without_relocations() { 662void test_moved_without_relocations() {
663 auto img = make_image(); 663 auto img = make_image();
664 auto* nt = nt_of(img); 664 auto* nt = nt_of(img);
@@ -706,7 +706,7 @@ void test_moved_without_relocations() {
706 if (held) VirtualFree(held, 0, MEM_RELEASE); 706 if (held) VirtualFree(held, 0, MEM_RELEASE);
707 { 707 {
708 // At a free base such an image maps, as it did before. Not Windows parity: the Windows 11 loader refused these 708 // At a free base such an image maps, as it did before. Not Windows parity: the Windows 11 loader refused these
709 // DLLs (error 487) at a free base too, for a reason not yet known (#8847); runtime/README.md keeps the question. 709 // DLLs (error 487) at a free base too, for a reason not yet known; runtime/README.md keeps the question.
710 auto stripped = img; 710 auto stripped = img;
711 nt_of(stripped)->FileHeader.Characteristics |= IMAGE_FILE_RELOCS_STRIPPED; 711 nt_of(stripped)->FileHeader.Characteristics |= IMAGE_FILE_RELOCS_STRIPPED;
712 expect_loads("an image with IMAGE_FILE_RELOCS_STRIPPED and no relocations maps at its free base", stripped); 712 expect_loads("an image with IMAGE_FILE_RELOCS_STRIPPED and no relocations maps at its free base", stripped);