mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:40:52 +01:00
[PR #643] [MERGED] OLD-7423: restore old upstream PR 7423 - pe_loader: trace delay imports bound to an unimplemented thunk; document delay-load and thread order #683
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#683
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/643
Author: @aslan2142
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142
Base:
main← Head:delay-import-thread-order-notes📝 Commits (3)
82d6883pe_loader: trace delay imports bound to an unimplemented thunk; note delay-load and thread-attach orderafea666Merge main into delay-import-thread-order-notes722fee9Merge main into delay-import-thread-order-notes (#643)📊 Changes
5 files changed (+133 additions, -9 deletions)
View changed files
📝
docs/runtime_imports.md(+16 -0)📝
runtime/README.md(+3 -1)📝
runtime/shims/startup_trace.h(+5 -4)📝
runtime/src/pe_loader.cpp(+10 -3)📝
runtime/test/startup_trace_test.cpp(+99 -1)📄 Description
Claimed in the coordination issue as: OLD-7423 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129211250
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).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.