Skip to content

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

@sbomer

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

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