Skip to content

Use bundle extraction path for CoreLib fallback in BindToSystem#128278

Open
elinor-fung wants to merge 2 commits into
dotnet:mainfrom
elinor-fung:binder-corelib-fallback-bundle-extraction
Open

Use bundle extraction path for CoreLib fallback in BindToSystem#128278
elinor-fung wants to merge 2 commits into
dotnet:mainfrom
elinor-fung:binder-corelib-fallback-bundle-extraction

Conversation

@elinor-fung
Copy link
Copy Markdown
Member

@elinor-fung elinor-fung commented May 16, 2026

When the primary lookup of System.Private.CoreLib.dll in the system directory (the directory CoreCLR was loaded from) fails, the binder previously fell back to scanning the TRUSTED_PLATFORM_ASSEMBLIES value for a matching simple name. This fallback was originally added in #42435 specifically for the self-contained single-file app with extracted contents (IncludeAllContentForSelfExtract=true) case - CoreCLR is statically linked into the host executable, so SystemDirectory points at the host directory, but the extracted CoreLib lives in the bundle extraction directory.

Look directly in the bundle extraction directory in that case instead of scanning the TPA list.

cc @dotnet/appmodel @AaronRobinsonMSFT

For a Hello, World! self-contained single-file app published with IncludeAllContentForSelfExtract=true, the framework's deps.json had System.Private.CoreLib at runtime asset position 98 of 182. Per process startup, the old fallback did:

What Allocations Bytes
StackSString copy of the TPA list 1 ~26 KB
outPath SString per GetNextTPAPath iteration 98 ~14 KB
simpleName SString per iteration 98 ~5 KB
Incidentals (Normalize, comparisons, etc.) ~12 ~200 B
Total ~209 ~38 KB

Measured via a DYLD_INSERT_LIBRARIES malloc/calloc/realloc interposer over 5 fresh runs each (osx-arm64 Release):

Variant Total allocations Total bytes allocated
Before 25,425 ± 2 ~9,022 KB
After 25,216 ± 2 ~8,984 KB
Saved ~209 ~38 KB

The savings scale with TPA list size and CoreLib's position in it: roughly 1 large (TPA copy) + 2k small allocations for k entries scanned before CoreLib.

When the primary lookup of System.Private.CoreLib.dll in the system
directory fails, the binder previously scanned the TRUSTED_PLATFORM_ASSEMBLIES
list (queried from the CLR config knobs) for a matching simple name. The
case this fallback was originally added for (PR dotnet#42435) is the single-file
app with extracted contents (IncludeAllContentForSelfExtract): CoreCLR is
statically linked into the host executable so SystemDirectory points at
the host directory, but the extracted CoreLib lives in the bundle
extraction directory.

Look directly in the bundle extraction directory in that case instead of
scanning the TPA list.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates CoreCLR's system assembly binding fallback for extracted single-file bundles: instead of scanning TRUSTED_PLATFORM_ASSEMBLIES when System.Private.CoreLib.dll is not beside CoreCLR/the host, it probes the known bundle extraction directory directly.

Changes:

  • Removes the configuration.h dependency previously needed for reading the TPA list.
  • Replaces the TPA-list scan fallback with Bundle::AppBundle->ExtractionPath() when the app is a bundle with extracted files.
  • Preserves the primary lookup and tracing flow for the normal system-directory/bundle-probe paths.
Show a summary per file
File Description
src/coreclr/binder/assemblybindercommon.cpp Updates BindToSystem CoreLib fallback logic for extracted single-file bundles.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

On targets where corerun enables the external assembly probe (browser-wasm),
the runtime invokes the probe with the simple assembly name during
BindToSystem (e.g. "System.Private.CoreLib.dll"). The probe previously
only populated its core_root/core_libs search paths in APP_ASSEMBLIES=EXTERNAL
mode, so in default PROPERTY mode the probe couldn't resolve a simple name
when BrowserHost_ExternalAssemblyProbe (which reads from FS by path) failed.

Always populate s_core_root_path/s_core_libs_path when the external probe
is enabled, regardless of APP_ASSEMBLIES mode. This lets the probe satisfy
the BindToSystem CoreLib lookup on browser-wasm where CoreCLR is statically
linked into corerun and SystemDomain::SystemDirectory() is empty.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants