Skip to content

Add XML output for retained type maps in ILC and ILLink - #135275

Open
simonrozsival wants to merge 3 commits into
mainfrom
simonrozsival-type-map-diagnostics
Open

simonrozsival wants to merge 3 commits into
mainfrom
simonrozsival-type-map-diagnostics

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Adds opt-in XML output describing the type maps retained by ILC and ILLink, including external and proxy mappings grouped by universe.

This gives downstream build tools, such as Android’s R8 integration, the information needed to keep generated wrappers for surviving mappings without relying on dependency graphs or trimmed-assembly inspection.

Enable it with TypeMapGenerateXmlFile=true in SDK builds or --output-typemaps on the command line. The XML is an intermediate build artifact, not part of the published application, and does not change trimming behavior.

The output uses a common XML format for both ILC and ILLink:

<typemaps version="1">
  <group type="Example.JavaUniverse,Example.Interop">
    <external>
      <entry key="example/MainActivity" value="Example.MainActivity,Example.App" />
    </external>
    <proxy>
      <entry key="Example.MainActivity,Example.App" value="Example.JavaProxy,Example.Interop" />
    </proxy>
  </group>
  <group type="Example.OtherUniverse,Example.Interop">
    <external>
      <entry key="other/Widget" value="Example.Widget,Example.App" />
    </external>
  </group>
</typemaps>

The root declares the format version, and each universe has separate sections for external (string → Type) and proxy (Type → Type) mappings. External keys are preserved verbatim. Managed types use reflection-style names with simple assembly qualification.

Closes #120204

/cc @rolfbjarne

Note

This PR description was drafted with GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Oct 6, 2026
@dotnet-policy-service dotnet-policy-service Bot added the linkable-framework Issues associated with delivering a linker friendly framework label Oct 6, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 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.

Comment thread docs/tools/illink/data-formats.md Outdated
Comment thread docs/tools/illink/data-formats.md Outdated
Comment thread src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCases/TypeMapArtifactTests.cs Outdated
Comment thread src/coreclr/tools/aot/ILCompiler/Program.cs Outdated
Comment thread src/coreclr/tools/aot/ILCompiler/Program.cs Outdated
Comment thread src/tools/illink/src/ILLink.Shared/SharedStrings.resx Outdated
Comment thread src/tools/illink/src/ILLink.Shared/TypeMapXmlWriter.cs Outdated
Comment thread src/tools/illink/src/ILLink.Shared/TypeMapXmlWriter.cs Outdated
Comment thread src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypeMapOutput.cs Outdated
Integrate NativeAOT output with ObjectDumper, pass the configured output path to both tools, and use shared library trimming tests for runtime, XML, and build-lifecycle coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival

Copy link
Copy Markdown
Member Author

@MichalStrehovsky thanks for the review. Your suggestions helped simplify this quite a bit.

ILC now uses an ObjectDumper, registered alongside the existing dumpers, and enumerates retained entries through the map nodes. The separate post-compilation export path and local exception handler are gone, so errors retain their full stack.

The output path comes from TypeMapXmlFile in MSBuild and is passed explicitly to both tools through --output-typemaps <file>. Neither tool guesses the filename anymore.

I moved the tests into the existing library trimming test so the same C# source checks runtime behavior and XML with both ILC and ILLink. The XML is copied beside the executable only for testing. This also covers cross-assembly mappings and universe isolation. The custom compiler/process harnesses and artificial metadata-name and null-key cases are gone.

The extra type-name handling was an attempt to account for hypothetical unusual metadata names. I removed those special cases and the documentation caveat; ILC uses its existing formatter. I also removed the speculative unsupported-type diagnostic and format version, restored platform-default line endings, and moved the ILLink-only escaping helper out of the shared writer.

Note

This comment was drafted with GitHub Copilot.

Generate the optional Import element only when additional targets are specified, avoiding empty Project attributes in other trimming test projects.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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 linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeMap API: For trimmed and nativeaot builds, provide a list of the types kept by the typemap

2 participants