Skip to content

Commit 40a8eba

Browse files
ivanpovazanGitHub Actions Autoformatter
andauthored
Do not enable dedup when targeting maccatalyst-x64 (#20945)
## Description This is a follow-up PR to: #20936 We should not enable dedup when targeting `maccatalyst-x64` because in case when the project file specifies `MtouchInterpreter=all,-System.Private.CoreLib`, the build will run the full AOT compiler with interpreter enabled. In this setup the runtime is configured to run in interp only mode: https://github.com/xamarin/xamarin-macios/blob/97a91cc4e3bf7cf8a4c657ca00ece620f2e28e91/tools/common/Target.cs#L812-L813 which means that during runtime, AOT images will be ignored - aot runtime will load them but mark them as unusuable since they are compiled with `full` compiler switch and the code falls back to interpreter (ref: https://github.com/dotnet/runtime/blob/efebf202a4a9bd78702bf4bf28a027f093e15d89/src/mono/mono/mini/aot-runtime.c#L2131-L2148 ) This is problematic for the `aot-instances` container image, which has a special handling at the runtime and does not accept it to be marked as unusable (we might want to revisit this in the future): https://github.com/dotnet/runtime/blob/efebf202a4a9bd78702bf4bf28a027f093e15d89/src/mono/mono/mini/aot-runtime.c#L2527-L2529 ## Changes This PR disables dedup optimization when targeting `maccatalyst-x64` and updates the required tests to match the behavior. --- Backports: - [x] #20946 - [x] Original reenabling of dedup for .NET 9 already includes these changes: #20941 --------- Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
1 parent 97a91cc commit 40a8eba

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

dotnet/targets/Xamarin.Shared.Sdk.targets

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,13 @@
11001100
<_AOTInputDirectory>$(_IntermediateNativeLibraryDir)aot-input/</_AOTInputDirectory>
11011101
<_AOTOutputDirectory>$(_IntermediateNativeLibraryDir)aot-output/</_AOTOutputDirectory>
11021102

1103-
<!-- Enable dedup optimization whenever we run AOT compiler -->
1104-
<_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == '' And '$(_RunAotCompiler)' == 'true' And '$(IsMacEnabled)' == 'true'">true</_IsDedupEnabled>
1103+
<!--
1104+
Enable dedup optimization whenever we run AOT compiler
1105+
The only exception is maccatalyst-x64 which uses AOT when the interpreter is also enabled.
1106+
In such setup, during runtime, AOT images are loaded but marked as unusuable as they are compiled with `full` compiler switch and the code fallsback to interpreter.
1107+
Dedup AOT image is specially handled by the AOT runtime and it is not allowed to have it marked as unusuable.
1108+
-->
1109+
<_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == '' And '$(_RunAotCompiler)' == 'true' And '$(IsMacEnabled)' == 'true' And '$(RuntimeIdentifier)' != 'maccatalyst-x64'">true</_IsDedupEnabled>
11051110
<_DedupAssembly Condition="'$(_IsDedupEnabled)' == 'true'">$(IntermediateOutputPath)aot-instances.dll</_DedupAssembly>
11061111

11071112
<!-- default to 'static' for Mac Catalyst to work around https://github.com/xamarin/xamarin-macios/issues/14686 -->

tests/dotnet/UnitTests/ProjectTest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,15 @@ public void DedupEnabledTest (ApplePlatform platform, string runtimeIdentifiers,
19841984
DotNet.AssertBuild (project_path, properties);
19851985

19861986
var objDir = GetObjDir (project_path, platform, runtimeIdentifiers);
1987-
Assert.True (FindAOTedAssemblyFile (objDir, "aot-instances.dll"), "Dedup optimization should be always enabled for AOT compilation");
1987+
if (platform == ApplePlatform.MacCatalyst) {
1988+
var objDirMacCatalystArm64 = Path.Combine (objDir, "maccatalyst-arm64");
1989+
Assert.True (FindAOTedAssemblyFile (objDirMacCatalystArm64, "aot-instances.dll"), $"Dedup optimization should be enabled for AOT compilation on: {platform} with RID: maccatalyst-arm64");
1990+
1991+
var objDirMacCatalystx64 = Path.Combine (objDir, "maccatalyst-x64");
1992+
Assert.False (FindAOTedAssemblyFile (objDirMacCatalystx64, "aot-instances.dll"), $"Dedup optimization should not be enabled for AOT compilation on: {platform} with RID: maccatalyst-x64");
1993+
} else {
1994+
Assert.True (FindAOTedAssemblyFile (objDir, "aot-instances.dll"), $"Dedup optimization should be enabled for AOT compilation on: {platform} with RID: {runtimeIdentifiers}");
1995+
}
19881996

19891997
var appExecutable = GetNativeExecutable (platform, appPath);
19901998

0 commit comments

Comments
 (0)