loader: bind delay-load imports at map time #3

Open
github-bot wants to merge 3 commits from github-bot/gh-3 into main AGit
Owner

@⁠FZNull on GitHub · 2026-11-23 00:43 UTC · original
FZNull:phase1/delay-import-binding → main · +110 −22 · 4 files · 3 commits · open

Change

Fixes #1. Delay-load imports are now bound at map time, the same way regular imports are.

src/formats/pe/directories.cpp already parsed the delay-load directory and reported each descriptor's module, iat_rva and symbols (or a status when the descriptor has no name table). MappedImage recorded only the module names under imports.delay_load_modules_untouched and left the IAT slots unresolved.

src/loader/image.cpp now runs one binding pass over both import lists. For each delay descriptor with a name table, every IAT slot receives options.resolve(module, symbol), or the same unresolved_tag | n placeholder the regular imports use, with a per-symbol entry in the report. The name table (INT) is left untouched, so a host delay helper could still resolve later. The mapper runs no code, so the lazy __delayLoadHelper2 path stays out of scope and out of the change.

The mapping report gains a root-level delay_imports object with slots, resolved, unresolved and modules_without_symbols (the last one keeps the pe::inspect status for descriptors without a name table). The old imports.delay_load_modules_untouched key is removed; nothing in the tree read it, and imports otherwise keeps its shape.

Descriptor layout and the RVA attribute bit follow the Microsoft PE Format documentation, Delay-Load Import Tables (Image Only).

Tests

tests/loader_image.cpp gains one test with three sections, using the corpus delay fixture (KERNEL32.dll regular; dxcompiler_xs.dll ordinal #1 and title-local.dll Probe delayed):

  • no resolver: both slots get placeholders ((value >> 47) != 0, so calling one faults), the two unresolved entries carry the right module, symbol and slot_va, and regular imports.slots is unchanged;
  • partial resolver: the resolved slot holds the returned address, the missing symbol keeps the placeholder, resolved == 1;
  • a descriptor whose name table RVA is zeroed: its IAT is not bound, it lands in modules_without_symbols with the pe::inspect status preserved, and slots == 1.

ROADMAP.md marks the item done and ARCHITECTURE.md says which part is still missing (the lazy helper).

Verification

Built and tested on Windows 11 build 26300.9974, MSVC 14.50.35717 (VS Build Tools 2026), CMake 4.5.1 + Ninja 1.13.2.

cmake -S . -B build/ninja -G Ninja -DCMAKE_BUILD_TYPE=Release   -> configure OK
cmake --build build/ninja --parallel 8                         -> 51/51, exit 0
ctest --test-dir build/ninja -C Release --output-on-failure    -> 2/2 passed (fixture, parsers = 37 Catch cases), no skips
clang-format 18.1.8 --dry-run --Werror src/loader/image.cpp tests/loader_image.cpp -> exit 0

Command-line evidence with the corpus delay.pe fixture:

  • xvboot bind delay.pe is identical before and after: the plan does not read the loader report.
  • xvboot map delay.pe before: delay_load_modules_untouched: ["dxcompiler_xs.dll", "title-local.dll"], delay slots unbound.
  • xvboot map delay.pe after: delay_imports reports slots: 2, resolved: 0 and the two unresolved entries (dxcompiler_xs.dll #1, title-local.dll Probe) with slot_value = 0x4000000000000000|slot; the regular imports section is unchanged.

No game files, dumps or SDK content are involved; the fixture is generated by tests/corpus/generate.py.

AI-assisted.

**@⁠FZNull** on GitHub · 2026-11-23 00:43 UTC · [original](https://github.com/sammwyy/xvalkyrie/pull/3) `FZNull:phase1/delay-import-binding` → `main` · +110 −22 · 4 files · 3 commits · open ## Change Fixes #1. Delay-load imports are now bound at map time, the same way regular imports are. `src/formats/pe/directories.cpp` already parsed the delay-load directory and reported each descriptor's `module`, `iat_rva` and `symbols` (or a `status` when the descriptor has no name table). `MappedImage` recorded only the module names under `imports.delay_load_modules_untouched` and left the IAT slots unresolved. `src/loader/image.cpp` now runs one binding pass over both import lists. For each delay descriptor with a name table, every IAT slot receives `options.resolve(module, symbol)`, or the same `unresolved_tag | n` placeholder the regular imports use, with a per-symbol entry in the report. The name table (INT) is left untouched, so a host delay helper could still resolve later. The mapper runs no code, so the lazy `__delayLoadHelper2` path stays out of scope and out of the change. The mapping report gains a root-level `delay_imports` object with `slots`, `resolved`, `unresolved` and `modules_without_symbols` (the last one keeps the `pe::inspect` status for descriptors without a name table). The old `imports.delay_load_modules_untouched` key is removed; nothing in the tree read it, and `imports` otherwise keeps its shape. Descriptor layout and the RVA attribute bit follow the Microsoft PE Format documentation, [Delay-Load Import Tables (Image Only)](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#delay-load-import-tables-image-only). ## Tests `tests/loader_image.cpp` gains one test with three sections, using the corpus `delay` fixture (`KERNEL32.dll` regular; `dxcompiler_xs.dll` ordinal `#1` and `title-local.dll` `Probe` delayed): - no resolver: both slots get placeholders (`(value >> 47) != 0`, so calling one faults), the two `unresolved` entries carry the right module, symbol and `slot_va`, and regular `imports.slots` is unchanged; - partial resolver: the resolved slot holds the returned address, the missing symbol keeps the placeholder, `resolved == 1`; - a descriptor whose name table RVA is zeroed: its IAT is not bound, it lands in `modules_without_symbols` with the `pe::inspect` status preserved, and `slots == 1`. ROADMAP.md marks the item done and ARCHITECTURE.md says which part is still missing (the lazy helper). ## Verification Built and tested on Windows 11 build 26300.9974, MSVC 14.50.35717 (VS Build Tools 2026), CMake 4.5.1 + Ninja 1.13.2. ```text cmake -S . -B build/ninja -G Ninja -DCMAKE_BUILD_TYPE=Release -> configure OK cmake --build build/ninja --parallel 8 -> 51/51, exit 0 ctest --test-dir build/ninja -C Release --output-on-failure -> 2/2 passed (fixture, parsers = 37 Catch cases), no skips clang-format 18.1.8 --dry-run --Werror src/loader/image.cpp tests/loader_image.cpp -> exit 0 ``` Command-line evidence with the corpus `delay.pe` fixture: - `xvboot bind delay.pe` is identical before and after: the plan does not read the loader report. - `xvboot map delay.pe` before: `delay_load_modules_untouched: ["dxcompiler_xs.dll", "title-local.dll"]`, delay slots unbound. - `xvboot map delay.pe` after: `delay_imports` reports `slots: 2, resolved: 0` and the two `unresolved` entries (`dxcompiler_xs.dll #1`, `title-local.dll Probe`) with `slot_value` = `0x4000000000000000|slot`; the regular `imports` section is unchanged. No game files, dumps or SDK content are involved; the fixture is generated by `tests/corpus/generate.py`. _AI-assisted._
Each delay import descriptor with a name table binds its IAT slots exactly
like the regular imports: the resolver's answer, or the unresolved_tag
placeholder recorded per symbol. The mapping report gains a delay_imports
section with slots/resolved/unresolved counts and keeps the inspect status
of descriptors without a name table. Refs sammwy/xvalkyrie#1
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:46:11 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3/head:github-bot/gh-3'
git switch 'github-bot/gh-3'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3'
git switch 'github-bot/gh-3'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3'
git switch 'github-bot/gh-3'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3'
git switch 'main'
git merge --squash 'github-bot/gh-3'
git switch 'main'
git merge --ff-only 'github-bot/gh-3'
git switch 'main'
git merge 'github-bot/gh-3'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/sammwyy--xvalkyrie!3
No description provided.