镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Trim netcoreapp libraries against implementations - #136495

Merged
sbomer merged 11 commits into
dotnet:mainfrom
am11:illink-impl-references
Nov 12, 2026
Merged

sbomer merged 11 commits into
dotnet:mainfrom
am11:illink-impl-references

Conversation

@am11

@am11 am11 commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Generic version of @#136476.

Library main Branch Diff
System.ComponentModel.TypeConverter 308,224 307,712 −512
System.Diagnostics.Process 158,720 158,208 −512
System.Formats.Tar 106,496 105,984 −512
System.IO.Compression 189,440 188,416 −1,024
System.IO.FileSystem.DriveInfo 38,912 38,400 −512
System.Linq.Parallel 215,552 215,040 −512
System.Net.Http 579,584 579,072 −512
System.Net.NameResolution 93,184 92,672 −512
System.Net.Ping 41,984 41,472 −512
System.Net.Quic 154,624 150,528 −4,096
System.Net.Security 371,200 370,176 −1,024
System.Net.Sockets 211,968 208,384 −3,584
System.Runtime.InteropServices 54,784 53,248 −1,536
System.Runtime.Numerics 208,896 203,264 −5,632
System.Security.Cryptography 1,129,472 1,125,376 −4,096
System.Text.RegularExpressions 384,512 384,000 −512
System.Threading.Tasks.Parallel 48,640 48,128 −512
Total (all DLLs) 33,018,368 32,992,256 −26,112

@am11
am11 requested a review from sbomer as a code owner October 27, 2026 00:06
@github-actions github-actions Bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Oct 27, 2026
@dotnet-policy-service dotnet-policy-service Bot added linkable-framework Issues associated with delivering a linker friendly framework community-contribution Indicates that the PR has been added by a community member labels Oct 27, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@am11

am11 commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

@jkotas, @agocke, this generic approach is more profitable compared to #136476, but comes with bit of a noise. It skips over AppContext switches.

@am11
am11 requested a review from jkotas October 28, 2026 23:45
@jkotas

jkotas commented Oct 28, 2026

Copy link
Copy Markdown
Member

@sbomer Could you please take a look?

# Conflicts:
#	src/coreclr/vm/wasm/wasi/callhelpers-pinvoke.cpp

@sbomer sbomer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to somehow prevent baking in constants from an OOB library that might change across versions?

Comment thread eng/illink.targets Resolved
Comment thread eng/illink.targets Resolved
Comment thread eng/illink.targets Resolved
am11 added 2 commits October 29, 2026 22:33
- Use the reference assembly of packable libraries, which can be replaced by a newer package at run time.
- Trim after CoreCompile with the implementation references as inputs, so changes to them are picked up incrementally.
- Don't disable the optimization when BuildAllConfigurations is set, which -pack sets for shipping builds.
- Allow --ignore-substitutions in the cacheable ILLink task arguments.
- Make not updating reference scopes the default in library mode instead of a new option.
@am11

am11 commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Do we need to somehow prevent baking in constants from an OOB library that might change across versions?

Packable libraries now contribute their reference assembly instead of the implementation.

Comment thread eng/illink.targets Resolved
Comment thread eng/illink.targets Resolved
am11 added 2 commits November 6, 2026 13:36
- Don't trim packable libraries against implementations, as their assets run on any OS.
- Build the best flavor separately so that its implementation isn't added to the closure.

@sbomer sbomer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Disabling scope rewriting for all library-mode runs can leave broken references when dependency sweeping removes a required facade or forwarder.

2 open issues
What changed in this PR

This PR generalizes the OS-check trimming approach from #136476 by trimming shared-framework libraries against implementation assemblies, enabling more constant propagation and reporting a 25,088-byte reduction across DLLs.

Changes:

  • Resolves target-OS implementation dependencies and reruns trimming when those inputs change.
  • Preserves original reference scopes and prevents library builds from folding unset feature switches.
  • Updates cache-argument handling, adds task tests, and removes unused WASI interop entries and thunks.
File Description
src/​tools/​illink/​test/​ILLink.Tasks.Tests/​ILLink.Tasks.Tests.cs Tests cache-key handling of substitution options.
src/​tools/​illink/​src/​linker/​Linker/​MemberActionStore.cs Detects feature-switch getters without explicit settings.
src/​tools/​illink/​src/​linker/​Linker/​LinkContext.cs Tracks library roots and reference-scope policy.
src/​tools/​illink/​src/​linker/​Linker.Steps/​UnreachableBlocksOptimizer.cs Prevents folding unset feature switches in library mode.
src/​tools/​illink/​src/​linker/​Linker.Steps/​SweepStep.cs Supports retaining original assembly reference scopes.
src/​tools/​illink/​src/​linker/​Linker.Steps/​RootAssemblyInputStep.cs Enables scope preservation for library roots.
src/​tools/​illink/​src/​ILLink.Tasks/​LinkTask.cs Allows substitution options in cacheable arguments.
src/​coreclr/​vm/​wasm/​wasi/​callhelpers-pinvoke.cpp Removes unused native entries and updates consumer comments.
src/​coreclr/​vm/​wasm/​wasi/​callhelpers-interp-to-managed.cpp Removes two unused call-helper signatures.
eng/​illink.targets Resolves implementation dependencies and coordinates incremental trimming.

Review effort: Balanced

@jkotas

jkotas commented Nov 7, 2026

Copy link
Copy Markdown
Member

"The checked-in CoreCLR WebAssembly call helpers" build failure looks related to the changes in the PR

@jkotas

jkotas commented Nov 7, 2026

Copy link
Copy Markdown
Member

ILLink tests failing

Expected the assembly impl.dll to not exist in /__w/1/s/artifacts/bin/ILLink.testcases/linker_tests/Libraries/LibraryModeFeatureSwitchConstants/output, but it did

@am11

am11 commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

@jkotas that failure was ILTrim (CLR_Tools_Tests) reusing the Mono.Linker case — ILTrim doesn't fold trivial feature-switch constants yet, so the case is on ILTrimExpectedFailures and skips there. illink's LibraryModeFeatureSwitchConstants still runs and passes.

@jkotas
jkotas requested a review from sbomer November 7, 2026 19:20
@jkotas

jkotas commented Nov 7, 2026

Copy link
Copy Markdown
Member

@sbomer Could you please do another review (additional changes made since your signoff)?

@am11
am11 force-pushed the illink-impl-references branch from 33bdabc to 26dfdb5 Compare November 7, 2026 19:47
@am11
am11 force-pushed the illink-impl-references branch from 26dfdb5 to aad7305 Compare November 7, 2026 19:49
am11 and others added 2 commits November 10, 2026 14:38
A feature switch with a constant body can still be substituted at application
publish time. Instead, pass IsMultithreadingSupported=false explicitly for the
single-threaded browser and wasi flavors, and allow --feature in the cacheable
ILLink arguments.

Co-authored-by: Cursor <cursoragent@cursor.com>
@am11

am11 commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Wasi failure is unrelated (infra issue).

@sbomer

sbomer commented Nov 12, 2026

Copy link
Copy Markdown
Member

/ba-g "deadletter"

@sbomer
sbomer merged commit f4775e5 into dotnet:main Nov 12, 2026
156 of 159 checks passed
@am11
am11 deleted the illink-impl-references branch November 12, 2026 00:36
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers community-contribution Indicates that the PR has been added by a community member linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants