PE loader: an executable loaded as a library does not run its entry point #1672
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1682"
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?
Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T19:14:55Z.
When a title loads an executable from its folder as a library (
LoadLibraryof a.exethat is not the main image),load_game_dlllogged that it is not a DLL.init_dllthen still called the image's entry point with DllMain's arguments, so itsmainCRTStartupran on the calling thread. That either started a second copy of the program inside the process, or the load failed with "DllMain returned FALSE".Windows does not call that entry point. LoadLibraryW: "If the specified module is an executable module, static imports are not loaded; instead, the module is loaded as if by LoadLibraryEx with the DONT_RESOLVE_DLL_REFERENCES flag", and that flag means DllMain is not called. XCL's thread attach and detach already call the entry point only for a DLL (
m.is_dll); process attach now does the same.What is in it
crates/xcl/src/loader.rs:init_dllcalls the entry point only when the image is a DLL. Testan_exe_loaded_as_a_library_does_not_run_its_entry_point: an image without the DLL flag whose entry point returns 0 loads, and loads once.Tested
cargo test --workspace -- --test-threads=4onc8a4266: 859 passed, 0 failed, 42 ignored; SKIPPED:heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)an EXE loads as a library: "DllMain(xcl_exe_as_library.exe) returned FALSE"Regression run
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by mantavisual on 2026-11-24T20:47:03Z.
Test report for
c8a426675198on a machine with an NVIDIA GPU, which the PR lists as not tested.Tested
cargo test --workspace --locked --no-fail-fast -- --test-threads=4: 859 passed, 0 failed, 42 ignored. The new test ran.4178e88: 892 passed, 0 failed, 42 ignored.gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).Do the tests notice a broken fix?
DllMain(xcl_exe_as_library.exe) returned FALSE.loader::teststest fails.Not tested: AMD, retail title, a real executable loaded as a library.
AI use: Claude Code (Claude Opus 5.5) ran this on my machine, wrote the report and posted it for me.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T21:37:48Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by MiharaxD on 2026-11-24T21:44:20Z.
Test report on an NVIDIA card, head
c8a4266(onmainc160d86), which covers the "NVIDIA" line.Tested
cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4(debug) onc8a4266: 859 passed, 0 failed, 42 ignored (lib tests 810 / 0 / 22).gpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu_wave32_program_in_wave64_hardware(no wave64).an_exe_loaded_as_a_library_does_not_run_its_entry_pointpasses.Regression run
scripts/smoke.ps1 -Game <game folder> -Seconds 60(release builds, start screen, no input).mainisc160d86:main:
this PR's head:
Not tested
AI use: Claude Code (Claude Opus 5.5) built the PR, ran the tests and both smoke runs, read the logs and wrote this report; I checked it before posting.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T13:38:49Z.
Independent desktop NVIDIA verification of PR #1682 at head
c8a426675198493f21015fcd06567ff61a7847d6(1commit; exact parent & merge-base:c160d86ef2efe3a07e4dfb473e4fa72eafb413c0, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted tests & build (
c8a42667)cargo test --release -p xcl --lib -- --nocapture an_exe_loaded_as_a_library_does_not_run_its_entry_point(3 consecutive runs)1 passed; 0 failed; 0 ignored; 831 filtered out× 3 (0.00s,0.00s,0.00s,0skipped)cargo test --release -p xcl --lib -- --nocapture loader::(3 consecutive runs)3 passed; 0 failed; 0 ignored; 829 filtered out× 3 (0.00s,0.00s,0.00s,0skipped)cargo build --release -p xcl1m 23s, exit0,0new warnings inloader.rs)Paired quiet 60 s retail smoke (
title: 29640639)(Note:
scripts/smoke.ps1atc160d86epredates9683e7a6and printed the local folder basename ontitle:; replaced below with the standard9683e7a6title hash29640639, with all measured fields verbatim.)Exact parent & merge-base (
c160d86ef2efe3a07e4dfb473e4fa72eafb413c0, cached baseline on the same machine):PR #1682 (
c8a426675198493f21015fcd06567ff61a7847d6):Limits of coverage
an_exe_loaded_as_a_library_does_not_run_its_entry_pointand the fullloader::suite (3/3,0skipped) passed3/3, directly verifying thatinit_dllskips calling the entry point whenm.is_dllis false (so loading a non-DLL executable as a library maps cleanly without executingentry_rvaasDllMain) while preserving DLLDllMainbehavior.0device removals,0crashes, steady 60 Hz) without testing a real title loading a secondary.exeviaLoadLibrary; single-run frame/commit delta vs. the cached parent reflects normal startup variance.AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T14:12:39Z.
merge-check claim
head:
c8a4266751Imported from ivall/xcl. Originally posted by throny on 2026-11-28T14:26:30Z.
merge-check
base:
b937fbabhead:
c8a4266751merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2141 passed, 1 failed, 48 ignored (26 SKIPPED lines). The one failure is gpu::dxil::msaa_tests::direct_msaa_loads_precede_get_dimensions, which fails on main without this PR too (reported on #3093) and in every tree of this batch; the nine failures main had since #2959 are gone at
b937fbab. I did not runb937fbabalone: the last base-only run ise13d6250(2130 passed, 10 failed, 48 ignored).review: none blocking. Before, the entry point of any loaded image was called as a DllMain, so an executable loaded as a library ran its startup routine with DllMain arguments and a return of 0 failed the load; now such an image is mapped and its entry point is not run. The flag is the right one (the DLL bit of the file header), thread attach and detach already check it, and the changed function has one caller. Minor, not fixed: TLS callbacks still run and imports are still resolved for such an executable, which Windows does not do in that mode.
performance: none.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-30T01:11:53Z.
merge-check
base:
53e85fb124head:
c8a4266751merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2792 passed, 2 failed, 49 ignored; SKIPPED: 28 (mostly "no wave64"); failing:
hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipelinefails on the base53e85fbalone too (#2369's test againstlate_release, see #2369);hle::d3d12x::list_x::tests::mid_list_write64_wait64_split_avoids_cycle_and_reuses_spareshit E_OUTOFMEMORY (0x8007000E) in the parallel run and passes 3/3 alone on both trees. Neither is from this PR.review: none blocking, after reading the whole diff (
loader.rs).init_dllis called only fromload_game_dll(the title'sLoadLibrary), so the title's own executable is not affected, and an EXE loaded as a library still runs its TLS callbacks. The new test passes 3/3; with them.is_dllcondition removed (scratch) it fails with "DllMain(xcl_exe_as_library.exe) returned FALSE". Side note, from before this PR and not blocking:tls_installtreats every!is_dllimage as the title's executable and triestake_slot_zero, so an EXE loaded as a library would also try to take TLS slot 0. Also seen once: in my first suite run,e2e::incomplete_discovered_corpus_blocks_headless_title_entryhung, with itsxclchild spinning for 40 minutes. Afterwards it passed 3/3 alone on this merge and onmain, and the wholee2ebinary passed 5/5 on both, so I count it as a one-off rather than this PR.performance: none (one more condition at library load).
verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug / Claude Code (Claude Opus 5.5)