Repository navigation
OLD-7423: restore old upstream PR 7423 - pe_loader: trace delay imports bound to an unimplemented thunk; document delay-load and thread order - #643
Conversation
…delay-load and thread-attach order Delay imports are bound eagerly (deliberate: --dry-run shows the whole import surface). A delay-loaded DLL or function that nothing serves becomes an unimplemented thunk returning 0 at its first call, where Windows' delay-load helper raises 0xC06D007E / 0xC06D007F, which a title can catch for a fallback. The binding is unchanged; --trace now writes a delay_import_unimplemented event (module, import) for each such import at load, so the first boot names them before any image code runs. docs/runtime_imports.md gets two notes on where the loader differs from Windows: the eager delay binding above, and that DLL_THREAD_ATTACH reaches TLS callbacks in TLS slot order, which puts the executable before the DLLs it imports (Windows' order is undocumented). runtime/README.md lists the new trace event and now says the loader applies DIR64 and HIGHLOW relocations and rejects HIGH, LOW and HIGHADJ (old upstream 761). startup_trace_test gets a synthetic DLL with one ordinary and two delay imports (one missing, one bound to kernel32): exactly one delay_import_unimplemented event, naming the missing delay import. Findings by cynbun in the old upstream coordination issue (old upstream 7231). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reviewed 82d6883: read the full diff. One thing to fix: the branch no longer merges into current main. There is a conflict in Recommendation: Fix first |
runtime/shims/startup_trace.h: main added the tls_index0 example event and the exception's region/regs fields to the header comment; keep them, add this branch's delay_import_unimplemented example and renumber seq. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ProjectLeonida#634 rewrote the same runtime/README.md paragraph on the loader. Its text stays, and its relocation sentence takes this PR's wording: DIR64 and HIGHLOW relocations, the other types rejected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claimed in the coordination issue as: OLD-7423 #14 (comment)
Restoration of my original pull request, old upstream PR 7423 in
ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bc; one conflict in theruntime/README.mdtrace-event table, resolved by keeping main's newerxmem_attributesandxmem_physical_pagesrows and adding the new row above them, and the old#Nreferences in the commit message are now plain text ("old upstream 761", "old upstream 7231"). No code changes beyond the rebase.What and why
Loader::bind_imports(runtime/src/pe_loader.cpp), so--dry-runshows the whole import surface. A delay-loaded DLL or function that nothing serves becomes an unimplemented thunk, which returns 0 at its first call. On Windows, the delay-load helper would raise0xC06D007Eor0xC06D007Fthere instead, and a title can catch that and take a fallback. That fallback never runs here, and nothing reported it.--tracenow writes adelay_import_unimplementedevent (module,import) for each such import when the image is loaded, before any image code runs. The binding itself is unchanged. Ordinary imports give no such event.docs/runtime_imports.md: a new section on where the loader differs from Windows:DLL_THREAD_ATTACHreaches TLS callbacks in TLS slot order (DLL_THREAD_DETACHin reverse). A module takes its slot inmap_image, beforebind_importsloads its dependencies, so the executable's callbacks run before those of the DLLs it imports. Windows does not document its own order.runtime/README.md:DIR64andHIGHLOWrelocations and rejects the other types, which matches the relocation code on main.runtime/shims/startup_trace.h: the example trace in the header comment shows the new event.startup_trace_test: a synthetic DLL image with one ordinary import that nothing serves and two delay imports: one missing, one bound tokernel32!GetTickCount. The test expects exactly onedelay_import_unimplementedevent, naming the missing delay import.Tested
Linux, Wine 11.22.
startup_trace_testandgta6rt_tls_host.dllwere built with clang for the mingw target (x86_64-w64-mingw32). The MSVC/W4 /permissive-build is left to CI.mainat 21625bc: 26 checks, 7 failed.mainwith only this PR's test copied in: 30 checks, 9 failed. The 2 new delay-import checks fail.main.maintoo. They come from Wine and mingw limits (an SEH fault inside the vectored handler,OutputDebugStringW, and the access-violation event), not from this change.git diff --checkis clean, andpython -I scripts/check_no_game_data.pypasses on the changed files.GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)AI-assisted (Claude Code, Claude Opus 5.5).