diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-23 15:12:44 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-24 04:58:41 -0500 |
| commit | ca56a0d5eff2f6217a593babcfaff87d46daa15d (patch) | |
| tree | 6807765965a62150a371a00fb0d9ad33be4684da /runtime/src/base_reservation.h | |
| parent | 0ddf806359d30022a3152e61c93ed077212d25aa (diff) | |
pe_loader: a relocation table is applied whatever RELOCS_STRIPPED says (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>
Diffstat (limited to 'runtime/src/base_reservation.h')
| -rw-r--r-- | runtime/src/base_reservation.h | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/runtime/src/base_reservation.h b/runtime/src/base_reservation.h index 485cf5917..5ccfe1aaa 100644 --- a/runtime/src/base_reservation.h +++ b/runtime/src/base_reservation.h | |||
| @@ -63,10 +63,10 @@ inline void* commit_reserved(std::uint64_t base, std::uint64_t size) { | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | // The preferred range of `image` when it has no relocations and that range is not free in this process; nullopt | 65 | // The preferred range of `image` when it has no relocations and that range is not free in this process; nullopt |
| 66 | // when the image can be mapped as it is (or is not a readable PE32+, which the loader reports itself). "No | 66 | // when the image can be mapped as it is (or is not a readable PE32+, which the loader reports itself). Without a |
| 67 | // relocations" is either IMAGE_FILE_RELOCS_STRIPPED, which the loader refuses to move, or an empty relocation | 67 | // relocation directory the loader refuses to move an image that has IMAGE_FILE_RELOCS_STRIPPED, and moves one with |
| 68 | // directory with the flag clear, which it moves with nothing fixed up (as Windows does): that is right only for an | 68 | // the flag clear with nothing fixed up: that is right only for an image with no absolute addresses in it, so its |
| 69 | // image with no absolute addresses in it, so its range is kept free all the same. | 69 | // range is kept free either way. An image with a relocation table is moved and fixed up whatever the flag says. |
| 70 | inline std::optional<Range> needed(const std::filesystem::path& image) { | 70 | inline std::optional<Range> needed(const std::filesystem::path& image) { |
| 71 | std::ifstream file(image, std::ios::binary); | 71 | std::ifstream file(image, std::ios::binary); |
| 72 | IMAGE_DOS_HEADER dos{}; | 72 | IMAGE_DOS_HEADER dos{}; |
| @@ -78,8 +78,7 @@ inline std::optional<Range> needed(const std::filesystem::path& image) { | |||
| 78 | !nt.OptionalHeader.SizeOfImage) | 78 | !nt.OptionalHeader.SizeOfImage) |
| 79 | return std::nullopt; | 79 | return std::nullopt; |
| 80 | const auto& oh = nt.OptionalHeader; | 80 | const auto& oh = nt.OptionalHeader; |
| 81 | if (!(nt.FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) && | 81 | if (oh.NumberOfRvaAndSizes > IMAGE_DIRECTORY_ENTRY_BASERELOC && |
| 82 | oh.NumberOfRvaAndSizes > IMAGE_DIRECTORY_ENTRY_BASERELOC && | ||
| 83 | oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size) | 82 | oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size) |
| 84 | return std::nullopt; // relocatable: the loader moves it if the base is taken | 83 | return std::nullopt; // relocatable: the loader moves it if the base is taken |
| 85 | const Range r{oh.ImageBase, (static_cast<std::uint64_t>(oh.SizeOfImage) + 0xffff) & ~std::uint64_t{0xffff}}; | 84 | const Range r{oh.ImageBase, (static_cast<std::uint64_t>(oh.SizeOfImage) + 0xffff) & ~std::uint64_t{0xffff}}; |