Repository navigation
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 (ItsNotRexed#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 coordination issue (ItsNotRexed#7231). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
runtime/README.md conflicted in the --trace event table: main extended the xmem_attributes row and added xmem_physical_pages next to this branch's delay_import_unimplemented row. Both are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested
AI-assisted (Claude Code). |
|
Tested e1626ae on NVIDIA GeForce RTX 3060 (driver 617.14), Windows 11 26H2 (26300), MSVC 19.44.35229 (v143) + Ninja, RelWithDebInfo: Negative control: with only AI-assisted (Claude Code). |
Claimed in the coordination issue: #7231 (comment) (findings by cynbun: #7231 (comment)).
Depends on: none.
This covers findings 2, 3 and 4 of that comment. Finding 1 (API-set contract versions) is already handled by #7275, so it is not in this PR.
What and why
Loader::bind_importsbinds the delay-import table eagerly, on purpose, so--dry-runshows the whole import surface.LEONIDA_UNIMPLEMENTED=log).0xC06D007E(module) or0xC06D007F(procedure) at that call instead. A title can catch that and take a fallback, and the fallback never runs here.--tracenow names each such import when the image loads, before any image code runs.DLL_THREAD_ATTACH, TLS callbacks run in TLS slot order (on_host_thread_event), and detach runs in reverse.map_imageclaims the lowest free slot beforebind_importsloads the dependencies. So the executable's callbacks run before those of the DLLs it imports.runtime/README.mdstill said the loader applies onlyDIR64relocations. It now saysDIR64andHIGHLOWare applied and the other types are rejected.The change
runtime/src/pe_loader.cpp: inbind_thunks, a delay import whose binding isUnimplementedwrites adelay_import_unimplementedtrace event (module,importasdll!name). With the trace off, the cost is one relaxed load.docs/runtime_imports.md: a new subsection, "Delay imports and thread events: where the loader differs from Windows", with the two notes.runtime/README.md: the new event in the--tracetable, and the corrected relocation sentence.runtime/shims/startup_trace.h: the event in the example list at the top.runtime/test/startup_trace_test.cpp:test_delay_import_tracebuilds a synthetic DLL by hand with:kernel32!GetTickCount(bound to the host).delay_import_unimplementedevent, and that the event names the missing delay import. The ordinary missing import and the bound delay import give no event.Tests
These are local Linux checks: the runtime is cross-built with clang 23.1.5 for
x86_64-w64-mingw32(mingw-w64 v14, GCC 16.2.0 forgta6rt_tls_host.dll), and the tests run under Wine 11.22 (Staging). No GPU and no game files are needed.startup_trace_test:main+ the new test: 30 checks, 9 failed. The 2 new delay checks fail (got 0events).main(26 checks, 7 failed). They are the VEH/SEH checks (exception,OutputDebugStringW), which do not work in this clang-mingw build under Wine. They are not related to this change.loader_test(includes the delay-import bounds cases) on this branch: 88 checks, 0 failed.python -m unittest discover -s tests -p "test_docs_*.py": 36 tests. The two failures (docs/dev-tools.mdanchor andscripts/dev.pyflags) are the same onmain, in a file this PR does not touch. The newruntime_imports.mdanchor resolves.--dry-runof the retail executable with--trace, built frommainand from this branch. This ran offline (bwrap --unshare-net) with the package mounted read-only. Only counts are given here:shim=54 host=432 module=72 unimplemented=29for the executable. The summary also matches: 29 unimplemented imports,hresult=0 other=29.delay_import_unimplementedevents, so none of the retail delay imports binds to an unimplemented thunk today.Not tested
/W4 /permissive-). CI covers those.IMAGE_DELAYLOAD_DESCRIPTOR::Attributes.AllAttributes, which both the Windows SDK and the mingw-w64 headers define.Checklist
docs/design.md. (Not a translator change.)AI-assisted (Claude Code, Claude Opus 5.5).