pe_map: treat a relocation directory at address 0 as absent #170
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/171"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T17:55:21Z.
Change
Refs #77.
The thread on #77 settled on keeping Windows-compatible behavior for an empty relocation directory, and #115 pins that case. This PR covers a related case that neither #115 nor #122 handles: a base-relocation directory whose
VirtualAddressis 0 but whoseSizeis not.The Windows loader finds the directory with
RtlImageDirectoryEntryToData, which returns nothing for an address of 0 whatever theSize, so the image counts as relocation-free.pe_mapchecked only that the range fit in the image. It then parsed the headers at RVA 0 as relocation blocks: theMZsignature became a block withSizeOfBlock3, and the image was rejected as "bad relocation block".tools/pe_map.cpp: a relocation directory at address 0 is treated as empty. TheIMAGE_FILE_RELOCS_STRIPPEDcheck and the block walk are unchanged, so this does not overlap #122's block-size and trailing-byte checks.tests/cpu/native_map_check.py:check_reloc_address_zeropatches the directory address of areloc_routecopy to 0 and keeps the linkedSize. It reserves the preferred base, loads the copy withLoadLibraryExWand maps it withpe_map. Both must place it away from the preferred base and leave the single DIR64 pointer at its linked value. The copy has no entry point, so nothing in it runs. The new check is called next tocheck_delay_directoryand needs no newSTATUSentries.docs/experiments.md: one paragraph in thepe_mapsection.Verification
ctest --preset dev --no-tests=error -R '^cpu_native_map$' -Vat00a36b6on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100: passed, printingcpu_reloc_original.dll: relocation directory at address 0 with Size 12 is ignored by LoadLibraryExW and pe_map; both map away from 0x180000000 and leave the DIR64 entry at 0x180001000. The fullctest --preset dev --no-tests=errorpassed 86/86, withbvh_wave64_hardware,bvh_wave64_warpandwave_shuffle_warpskipped.tools/pe_map.cppwas compiled with clang++ against a minimalwindows.hstand-in (mmap-backedVirtualAlloc, stdio file reads). The fixture was a source-built DLL (clang --target=x86_64-pc-windows-msvcpluslld-link /dll /noentry) with one exported function pointer in.data, so it has a single DIR64 relocation. The relocation directory is at 0x4000 with Size 12, and ImageBase is 0x180000000.8ac95cf: the original maps and relocates the pointer. The copy with the directory address 0 fails with status 4, "bad relocation block".IMAGE_FILE_RELOCS_STRIPPEDset is still rejected with "relocations stripped".Evidence and follow-up
LoadLibraryExWcomparison incpu_native_mapon Windows 11 build 26200: the copy with the relocation directory address 0 and Size 12 loads away from the reserved preferred base, and its DIR64 pointer keeps the linked value, so the loader treats the image as having no relocations.main()in the same test file, while this PR adds one near the top. Inpe_map.cpp, the two changes touch neighboring but different lines.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T18:17:09Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
00a36b6ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T18:20:03Z.
The loader comparison is clear. Unlike the position-independent #115 control, this fixture retains an absolute pointer at the linked address after the image is mapped elsewhere. The observable success/failure policy is with the lead developer in #199.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-21T19:25:09Z.
Two observations from reading the diff at
00a36b6, without building it:The docs and the PR description disagree about the Windows run. The new paragraph in
docs/experiments.mdsays "The Windows half of this comparison has not been run yet" and describes a Linux build against awindows.hstand-in. The description reports the Windowscpu_native_maprun on build 26200, which printed the success line. If the Windows run is the evidence, the paragraph is out of date.A Size larger than the image now maps without a test. On
main,inside(relocs.VirtualAddress, relocs.Size, opt.SizeOfImage)rejects a directory at address 0 whoseSizeexceedsSizeOfImage, with "relocation directory outside image". With the substitution,relocsis the empty directory for anySize, so that image now maps. The test keeps the linkedSize, so it does not exercise this case. Whatever the success/failure policy settles on, a copy with address 0 andSize = SizeOfImage + 1, run under bothLoadLibraryExWandpe_map, would pin it down.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T03:50:00Z.
I verified both review cases with the Windows loader and pe_map, using the same source-built image and a reserved preferred base. With relocation RVA 0, both the linked size (12) and SizeOfImage+1 (28673) mapped elsewhere and retained the linked DIR64 value. For this API we match the observed Windows mapping behavior. The test only reads the slot. I added the oversized case and replaced the old experiment note with these results.