Skip to content

Conversation

@kotlarmilos
Copy link
Member

@kotlarmilos kotlarmilos commented Oct 31, 2025

Description

After #121187 Crossgen2 determines cross-compilation targets by reading Crossgen2Tool.GetMetadata(MetadataKeys.TargetOS). This code path triggers PerfMapWriter, which currentl doesn't support iOS targets. This PR disables PerfMap generation for Apple mobile platforms.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

@kotlarmilos
Copy link
Member Author

/cc: @jkoritzinsky Please let me know if this is good approach

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 adds support for Apple platform variants to the PerfMap writer by mapping additional Darwin-based operating systems (MacCatalyst, iOS, iOSSimulator, tvOS, tvOSSimulator) to the existing OSX PerfMapOSToken.

Key Changes

  • Maps five additional Apple platform variants to PerfMapOSToken.OSX in the switch expression
Comments suppressed due to low confidence (1)

src/coreclr/tools/aot/ILCompiler.Diagnostics/PerfMapWriter.cs:126

  • The switch expression is now missing a case for TargetOS.WebAssembly which exists in the TargetOS enum (defined in src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs). This will cause a NotImplementedException at runtime when WebAssembly is used as the target OS. Add a case for TargetOS.WebAssembly with an appropriate PerfMapOSToken mapping, or add test coverage to ensure all TargetOS values are handled.
            PerfMapOSToken osToken = details.OperatingSystem switch
            {
                TargetOS.Unknown => PerfMapOSToken.Unknown,
                TargetOS.Windows => PerfMapOSToken.Windows,
                TargetOS.Linux => PerfMapOSToken.Linux,
                TargetOS.OSX => PerfMapOSToken.OSX,
                TargetOS.MacCatalyst => PerfMapOSToken.OSX,
                TargetOS.iOS => PerfMapOSToken.OSX,
                TargetOS.iOSSimulator => PerfMapOSToken.OSX,
                TargetOS.tvOS => PerfMapOSToken.OSX,
                TargetOS.tvOSSimulator => PerfMapOSToken.OSX,
                TargetOS.FreeBSD => PerfMapOSToken.FreeBSD,
                TargetOS.NetBSD => PerfMapOSToken.NetBSD,
                TargetOS.SunOS => PerfMapOSToken.SunOS,
                _ => throw new NotImplementedException(details.OperatingSystem.ToString())
            };

@am11
Copy link
Member

am11 commented Oct 31, 2025

Shall we make

match or maybe dedup them if possible?

@jkoritzinsky
Copy link
Member

The PerfMap constants are part of the PerfMap format, so any changes would require versioning the format, which isn't worth doing for this case (especially as this format doesn't really make sense in this scenario)

@jkotas
Copy link
Member

jkotas commented Oct 31, 2025

especially as this format doesn't really make sense in this scenario

Should the right fix be to disable perfmap generation in these scenarios instead then?

@jkoritzinsky
Copy link
Member

The right fix would be to disable generation on the consumer side (ie don't pass the flag to emit PerfMaps).

Then we could block passing the flag to emit them for these platforms.

The iOS perf tests for CoreCLR aren't well configured at the moment though if they're hitting this. They're requesting ReadyToRun image generation even though it doesn't work as-is.

@jkotas
Copy link
Member

jkotas commented Oct 31, 2025

The right fix would be to disable generation on the consumer side (ie don't pass the flag to emit PerfMaps).

@kotlarmilos Can we do that instead this change?

Copy link
Member

@am11 am11 left a comment

Choose a reason for hiding this comment

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

PR title can be now changed to Disable PerfMap generation for Apple mobile platforms.

nodeFactoryFlags.PrintReproArgs = Get(_command.PrintReproInstructions);
nodeFactoryFlags.EnableCachedInterfaceDispatchSupport = Get(_command.EnableCachedInterfaceDispatchSupport);

// Disable PerfMap generation for Apple mobile platforms as they are not supported for ReadyToRun
Copy link
Member

@jkotas jkotas Nov 3, 2025

Choose a reason for hiding this comment

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

Can this be disabled in the script or makefile that calls crossgen instead?

Something is explicitly passing an option to generate a perfmap and we are not able to honor that request. We should print an error that it is not supported here. Silently ignoring command-line options is just causing confusion.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is enabled when PublishReadyToRunEmitSymbols is set:

if (!Crossgen2IsVersion5 && _emitSymbols)
{
if (Crossgen2Tool.GetMetadata(MetadataKeys.TargetOS) == "windows")
{
result.AppendLine("--pdb");
result.AppendLine($"--pdb-path:{Path.GetDirectoryName(_outputPDBImage)}");
}
else
{
result.AppendLine("--perfmap");
result.AppendLine($"--perfmap-path:{Path.GetDirectoryName(_outputPDBImage)}");
string perfmapFormatVersion = Crossgen2Tool.GetMetadata(MetadataKeys.PerfmapFormatVersion);
if (!string.IsNullOrEmpty(perfmapFormatVersion))
{
result.AppendLine($"--perfmap-format-version:{perfmapFormatVersion}");
}
}
}

PublishReadyToRunEmitSymbols is set unconditionally here:
https://github.com/dotnet/arcade/blob/6247a683b6e52f9c24e9c7b8832bb4cd3537e7f7/src/Microsoft.DotNet.SharedFramework.Sdk/targets/sharedfx.targets#L10

I disabled it for Apple mobile in the targets. For unsupported scenarios, I would prefer to fail compilation rather than handle it gracefully, since it should be fixed rather than worked around.

Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't seem to be enough, I think it is set in ReadyToRunCodegenCompilationBuilder as well

@kotlarmilos kotlarmilos changed the title Map Apple mobile targets to OSX in PerfMapWriter to support Crossgen2 compilation Disable PerfMap generation for Apple mobile platforms Nov 3, 2025
@kotlarmilos kotlarmilos enabled auto-merge (squash) November 3, 2025 15:42
kotlarmilos added a commit to kotlarmilos/runtime that referenced this pull request Nov 3, 2025
@kotlarmilos kotlarmilos disabled auto-merge November 4, 2025 08:15
@kotlarmilos kotlarmilos requested a review from jkotas November 4, 2025 09:01
Copy link
Member

Choose a reason for hiding this comment

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

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.

4 participants