OLD-7423: restore old upstream PR 7423 - pe_loader: trace delay imports bound to an unimplemented thunk; document delay-load and thread order #643
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!643
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/643/head"
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?
@aslan2142 on GitHub · 2026-11-24 10:48 UTC · original
aslan2142:delay-import-thread-order-notes→main· +133 −9 · 5 files · 3 commits · merged 2026-11-25 22:55 UTCClaimed in the coordination issue as: OLD-7423 #14
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 at21625bca8c; 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.mainat21625bca8: 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).
@PierreEbele on GitHub · 2026-11-25 01:48 UTC · original
Reviewed
82d6883: read the full diff.check_no_game_dataon the touched files is clean. A sandboxed probe rebuilds the new test's synthetic delay image and parses it withpe_inspect.py. On both main and this branch it finds the 3 imports the test asserts.resolve()pushes oneImportRecordper import, som.imports.back()is the import just bound. The docs match the code: relocation types, TLS-slot thread-event order and eager delay binding. On this head'swindowsCI job,startup_tracepasses. The job's only failure iscrt_timed_wait, which #831 has since fixed on main.One thing to fix: the branch no longer merges into current main. There is a conflict in
runtime/shims/startup_trace.h, in the header's example-event comment (theseqrenumbering), because #984 (273b3bdf) touched the same block. It is a comment-only rebase. No code findings. AI-assisted review.Recommendation: Fix first
@aslan2142 on GitHub · 2026-11-25 22:55 UTC · original
Merged:
pe_loadertraces delay imports bound to an unimplemented thunk; documents delay-load and thread order.mainmerged in. Theruntime/shims/startup_trace.hexample-event comment keepsmain'stls_index0event and the exception'sregion/regsfields, adds this PR'sdelay_import_unimplementedand renumbersseq(afea66650). It is a comment-only change.runtime/README.mdparagraph on the loader. After #634,mainwas merged in again: #634's paragraph stays, and its relocation sentence takes this PR's wording (IMAGE_REL_BASED_DIR64andHIGHLOW, rejecting the other types).main5fab93967with all nine of these runtime PRs merged together (#634, #643, #684, #657, #677, #638, #710, #688, #671), on llvmpipe and the gfx1036 iGPU (RADV): no test went from pass to fail.startup_traceandloaderpass on both.main21d3662ad+722fee9af: it merges cleanly; the semantic suite passes (493 files, 6,318 tests, 0 files failed); the 15 docs and writer tests pass;check_no_game_data.pyis clean on the 5 changed files.AI-assisted (Claude Code, Claude Opus 5.5).
latencyframes in flight while armed (mailbox replace) #671