Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

Fix Crossgen failure when compiling trimmed Mac Catalyst project

The issue occurs when crossgen tries to load intrinsic types that have been trimmed away during the compilation process. Specifically, System.Runtime.Intrinsics.Arm.Crc32 is being trimmed but crossgen still tries to load it with throwIfNotFound=true, causing a TypeLoadException.

Plan:

  • Understand the issue - crossgen fails when intrinsic types are trimmed
  • Locate the InstructionSetGenerator.cs file
  • Modify InstructionSetGenerator to handle missing types gracefully
    • Changed GetType(..., true) to GetType(..., false) so it returns null instead of throwing
    • Added null checks before yielding types
    • Handled both regular types and nested types
  • Regenerate the source files using ThunkGenerator tool
  • Build and test the changes
    • ThunkGenerator builds successfully
    • ILCompiler.ReadyToRun builds successfully with no warnings or errors
  • Run code review and security checks
    • Code review: No issues found
    • Security check: No code analysis issues detected
  • Address PR feedback
    • Reverted unnecessary JIT EE version GUID change

Summary:
The fix modifies the InstructionSetGenerator to generate code that gracefully handles missing (trimmed) intrinsic types. Instead of throwing a TypeLoadException when a type is not found, the code now:

  1. Calls GetType(..., false) which returns null for missing types
  2. Checks for null before yielding types to the enumerable
  3. Skips trimmed types entirely, allowing crossgen to complete successfully

This is the correct behavior - if a hardware intrinsic type has been trimmed away, it shouldn't be added to the compilation roots, and the build should succeed without that type.

Original prompt

This section details on the original issue you should resolve

<issue_title>Crossgen fails when compiling a trimmed Mac Catalyst project</issue_title>
<issue_description>### Description

Crossgen fails to compile a trimmed Mac Catalyst project with:

error Error: Failed to load type 'System.Runtime.Intrinsics.Arm.Crc32' from assembly 'System.Private.CoreLib'

Reproduction Steps

Use .NET 11 preview 1, install the mac catalyst workload, create a mac catalyst project, compile.

This script does it:

#!/bin/bash -eu

curl -LO https://ci.dot.net/public/Sdk/11.0.100-preview.1.26081.107/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64.tar.gz
mkdir dotnet
tar -xzf *.tar.gz -C dotnet

cat >NuGet.config <<EOF
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="macios10" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-macios-b364fe57/nuget/v3/index.json" />
    <add key="dotnet11" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet11/nuget/v3/index.json" />
    <add key="macios" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-macios-64064500/nuget/v3/index.json" />
    <add key="official" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <disabledPackageSources>
    <clear />
  </disabledPackageSources>
</configuration>
EOF

./dotnet/dotnet workload config --update-mode manifests
./dotnet/dotnet workload install maccatalyst
mkdir catalysttest
cd catalysttest
../dotnet/dotnet new maccatalyst
../dotnet/dotnet build -p:UseMonoRuntime=false -p:MtouchLink=SdkOnly

Expected behavior

Successful build.

Actual behavior

$ dotnet build -p:UseMonoRuntime=false -p:MtouchLink=SdkOnly -bl
Restore complete (0.5s)
    info NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  catalysttest net11.0-maccatalyst maccatalyst-arm64 failed with 16 error(s) (11.6s) → bin/Debug/net11.0-maccatalyst/maccatalyst-arm64/catalysttest.dll
    /Users/rolf/Downloads/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64/sdk/11.0.100-preview.1.26081.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(488,5): error Error: Failed to load type 'System.Runtime.Intrinsics.Arm.Crc32' from assembly 'System.Private.CoreLib'
    /Users/rolf/Downloads/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64/sdk/11.0.100-preview.1.26081.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(488,5): error Internal.TypeSystem.TypeSystemException+TypeLoadException: Failed to load type 'System.Runtime.Intrinsics.Arm.Crc32' from assembly 'System.Private.CoreLib'
    /Users/rolf/Downloads/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64/sdk/11.0.100-preview.1.26081.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(488,5): error    at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID, String, String)
    /Users/rolf/Downloads/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64/sdk/11.0.100-preview.1.26081.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(488,5): error    at Internal.TypeSystem.ResolutionFailure.Throw()
    /Users/rolf/Downloads/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64/sdk/11.0.100-preview.1.26081.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(488,5): error    at Internal.TypeSystem.Ecma.EcmaModule.GetType(ReadOnlySpan`1, ReadOnlySpan`1, NotFoundBehavior)
    /Users/rolf/Downloads/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64/sdk/11.0.100-preview.1.26081.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(488,5): error    at Internal.TypeSystem.ModuleDesc.GetType(ReadOnlySpan`1, ReadOnlySpan`1, Boolean)
    /Users/rolf/Downloads/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64/sdk/11.0.100-preview.1.26081.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(488,5): error    at Internal.JitInterface.InstructionSetParser.<LookupPlatformIntrinsicTypes>d__1.MoveNext()
    /Users/rolf/Downloads/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64/sdk/11.0.100-preview.1.26081.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(488,5): error    at ILCompiler.ReadyToRunHardwareIntrinsicRootProvider.AddCompilationRoots(IRootingServiceProvider)
    /Users/rolf/Downloads/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64/sdk/11.0.100-preview.1.26081.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(488,5): error    at ILCompiler.Compilation..ctor(DependencyAnalyzerBase`1, NodeFactory, IEnumerable`1, ILProvider, DevirtualizationManager, IEnumerable`1, Logger, InstructionSetSupport)
    /Users/rolf/Downloads/dotnet-sdk-11.0.100-preview.1.26081.107-osx-arm64/sdk/11.0.100-preview.1.26081.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(488,5): error    at ILCompiler.ReadyToRunCodegenCompilation..ctor(DependencyAnalyzerBase`1, NodeFactory, IEnumerable`1, ILProvider, Logger, Devi...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes dotnet/runtime#123953

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/runtime/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Crossgen fails when compiling a trimmed Mac Catalyst project Fix Crossgen2 failure on trimmed intrinsic types Feb 3, 2026
Copilot AI requested a review from jkoritzinsky February 3, 2026 19:09
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI requested a review from jkotas February 3, 2026 19:52
@jkoritzinsky jkoritzinsky marked this pull request as ready for review February 3, 2026 21:10
Copilot AI review requested due to automatic review settings February 3, 2026 21:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a Crossgen2 failure that occurs when compiling trimmed Mac Catalyst projects where hardware intrinsic types like System.Runtime.Intrinsics.Arm.Crc32 have been trimmed away. The fix modifies the instruction set lookup code to gracefully handle missing types instead of throwing TypeLoadExceptions.

Changes:

  • Modified InstructionSetGenerator.cs to generate null-safe type lookup code
  • Regenerated CorInfoInstructionSet.cs with the updated template
  • Changed all GetType(..., true) calls to GetType(..., false) to return null instead of throwing
  • Added null checks before yielding types to the enumerable

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/coreclr/tools/Common/JitInterface/ThunkGenerator/InstructionSetGenerator.cs Updated code generator template to emit null-safe type lookups with proper null checks for both parent types and nested types
src/coreclr/tools/Common/JitInterface/CorInfoInstructionSet.cs Auto-generated file containing null-safe type lookup implementations for all instruction sets across ARM64, X64, and X86 architectures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants