Skip to content

Fix NativeAOT assembly name mangling collisions#130012

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-aot-compilation-error
Draft

Fix NativeAOT assembly name mangling collisions#130012
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-aot-compilation-error

Conversation

Copilot AI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

NativeAOT could generate duplicate mangled type names when different assembly names sanitized to the same C identifier, causing ILCompiler to fail with a duplicate-key exception.

  • Deterministically computes mangled assembly name prefixes from the compiler context’s input/reference assembly simple names.
  • Keys mangled assembly prefixes by assembly simple name strings without loading all reference assemblies.
  • Uses existing disambiguation for sanitized non-System.Private.* assembly names.
  • Preserves System.Private.*S.P.* mangling without disambiguation.
  • Adds end-to-end NativeAOT regression coverage under src/tests with colliding assembly names (A.B and A_B).

Validation

  • Baseline ./build.sh clr+libs+host
  • ./build.sh clr+libs+host
  • ./build.sh clr.aot+libs -rc Release -lc Release
  • src/tests/build.sh -nativeaot -test:nativeaot/SmokeTests/AssemblyNameCollision/AssemblyNameCollision.csproj x64 release
  • artifacts/tests/coreclr/linux.x64.Release/nativeaot/SmokeTests/AssemblyNameCollision/AssemblyNameCollision.sh

PR Checklist

  • Issues in this repository are used to track work and discussions. Please create or link to an issue.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 30, 2026 01:52
Copilot AI changed the title [WIP] Fix AOT compilation error related to duplicate keys Fix NativeAOT assembly name mangling collisions Jun 30, 2026
Copilot AI requested a review from MichalStrehovsky June 30, 2026 01:54

@MichalStrehovsky MichalStrehovsky 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.

Comment thread src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs Outdated
Comment thread src/coreclr/tools/aot/ILCompiler.Compiler.Tests/ILCompiler.Compiler.Tests.csproj Outdated
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 30, 2026 06:09

Copilot AI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Addressed the review feedback in b4734ac89: the mangler now keys by EcmaAssembly, and the unit test was replaced with an end-to-end NativeAOT test under src/tests.

@MichalStrehovsky MichalStrehovsky 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.

/// Dictionary given a mangled name for a given <see cref="TypeDesc"/>
/// </summary>
private Dictionary<TypeDesc, Utf8String> _mangledTypeNames = new Dictionary<TypeDesc, Utf8String>();
private Dictionary<EcmaAssembly, Utf8String> _mangledAssemblyNames = new Dictionary<EcmaAssembly, Utf8String>();

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.

Look like making this keyed on EcmaAssembly is problematic because we cannot load everything that is getting passed as input (some of the -r parameters specify garbage). Switch this back to being keyed on string where the string is the assembly file name without extension ("simple name").

</PropertyGroup>

<ItemGroup>
<Compile Remove="ManglerCollision.*\**" />

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.

Delete this line.

@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>

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.

Suggested change
<ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>0</CLRTestPriority>
</PropertyGroup>
<ItemGroup>

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 30, 2026 08:30
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 30, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants