Skip to content

ILLink: root assembly preserves referenced forwarders in other assemblies #126518

Closed

Description

@sbomer

Note

This issue was filed with AI (Copilot) assistance.

When an assembly is rooted with -a (AllMembers) and has link action, ILLink preserves type forwarder assemblies that are referenced through type references. This is unnecessary because the linker rewrites the type references to point directly to the implementation assembly, so the forwarder is not needed at runtime to load the assembly. Without -a, these forwarder assemblies are correctly removed.

Root Cause

MarkStep.MarkEntireAssembly unconditionally calls TypeReferenceMarker.MarkTypeReferences, which walks all type references in the assembly and calls MarkForwardedScope for each one. This marks the ExportedType entries in forwarder assemblies, which causes those assemblies to be preserved.

This is correct for copy/save action assemblies — they can't be rewritten, so forwarders they reference must be kept. But for root assemblies with link action, the type references will be rewritten by AssemblyReferencesCorrector in the sweep step to point directly to the implementation assemblies, making the forwarders unnecessary.

Encountered in dotnet/android@924649e

Activity

  1. dotnet-policy-service commented on Apr 3, 2026

    @dotnet-policy-service
    Contributor

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

  2. self-assigned this
    on Apr 3, 2026
  3. added this to the 11.0.0 milestone on Apr 3, 2026
  4. added a commit that references this issue on Apr 3, 2026
    8378d26
  5. sbomer commented on Jul 1, 2026

    @sbomer
    MemberAuthor

    Fixed by #126519.

  6. locked and limited conversation to collaborators on Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzersbug

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions