Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,9 @@

<_AOTInputDirectory>$(_IntermediateNativeLibraryDir)aot-input/</_AOTInputDirectory>
<_AOTOutputDirectory>$(_IntermediateNativeLibraryDir)aot-output/</_AOTOutputDirectory>
<!-- Enable dedup optimization only in FullAOT mode -->
<_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == '' And '$(_RunAotCompiler)' == 'true' And '$(MtouchInterpreter)' == '' And '$(IsMacEnabled)' == 'true'">true</_IsDedupEnabled>

<!-- Enable dedup optimization whenever we run AOT compiler -->
<_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == '' And '$(_RunAotCompiler)' == 'true' And '$(IsMacEnabled)' == 'true'">true</_IsDedupEnabled>
<_DedupAssembly Condition="'$(_IsDedupEnabled)' == 'true'">$(IntermediateOutputPath)aot-instances.dll</_DedupAssembly>

<!-- default to 'static' for Mac Catalyst to work around https://github.com/xamarin/xamarin-macios/issues/14686 -->
Expand Down
20 changes: 14 additions & 6 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,10 +1945,11 @@ public void RaisesAppDomainUnhandledExceptionEvent (ApplePlatform platform)
}
}

bool FindAssembly (string path, string dllName)
bool FindAOTedAssemblyFile (string path, string dllName)
{
foreach (string file in Directory.GetFiles (path, "*.dll", SearchOption.AllDirectories)) {
if (Path.GetFileName (file).Equals (dllName, StringComparison.OrdinalIgnoreCase)) {
var aotedAssemblyFileName = $"{dllName}.o";
foreach (string file in Directory.GetFiles (path, "*.o", SearchOption.AllDirectories)) {
if (Path.GetFileName (file).Equals (aotedAssemblyFileName, StringComparison.OrdinalIgnoreCase)) {
return true;
}
}
Expand All @@ -1959,11 +1960,17 @@ bool FindAssembly (string path, string dllName)
[Test]
[TestCase (ApplePlatform.iOS, "ios-arm64;", "-all,System.Private.CoreLib")]
[TestCase (ApplePlatform.iOS, "ios-arm64;", "all,-System.Private.CoreLib")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "-all,System.Private.CoreLib")]
[TestCase (ApplePlatform.iOS, "ios-arm64;", "-all")]
[TestCase (ApplePlatform.iOS, "ios-arm64;", "")]
// [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "-all,System.Private.CoreLib")] // Should be reenalbed once https://github.com/dotnet/runtime/issues/105510 gets fixed
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "all,-System.Private.CoreLib")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "-all")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-arm64;maccatalyst-x64", "")]
[TestCase (ApplePlatform.TVOS, "tvos-arm64;", "-all,System.Private.CoreLib")]
[TestCase (ApplePlatform.TVOS, "tvos-arm64;", "all,-System.Private.CoreLib")]
public void PartialAOTTest (ApplePlatform platform, string runtimeIdentifiers, string mtouchInterpreter)
[TestCase (ApplePlatform.TVOS, "tvos-arm64;", "-all")]
[TestCase (ApplePlatform.TVOS, "tvos-arm64;", "")]
public void DedupEnabledTest (ApplePlatform platform, string runtimeIdentifiers, string mtouchInterpreter)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Expand All @@ -1976,7 +1983,8 @@ public void PartialAOTTest (ApplePlatform platform, string runtimeIdentifiers, s

DotNet.AssertBuild (project_path, properties);

Assert.True (!FindAssembly (appPath, "aot-instances.dll"), "Dedup optimization shouldn't been enabled for partial AOT compilation");
var objDir = GetObjDir (project_path, platform, runtimeIdentifiers);
Assert.True (FindAOTedAssemblyFile (objDir, "aot-instances.dll"), "Dedup optimization should be always enabled for AOT compilation");

var appExecutable = GetNativeExecutable (platform, appPath);

Expand Down
2 changes: 1 addition & 1 deletion tools/common/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ public void GetAotArguments (string filename, Abi abi, string outputDir, string
bool enable_debug = app.EnableDebug;
bool enable_debug_symbols = app.PackageManagedDebugSymbols;
bool llvm_only = app.EnableLLVMOnlyBitCode;
bool interp = app.IsInterpreted (Assembly.GetIdentity (filename));
bool interp = app.IsInterpreted (Assembly.GetIdentity (filename)) && !(isDedupAssembly.HasValue && isDedupAssembly.Value);
bool interp_full = !interp && app.UseInterpreter;
bool is32bit = (abi & Abi.Arch32Mask) > 0;
string arch = abi.AsArchString ();
Expand Down
6 changes: 4 additions & 2 deletions tools/common/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -774,15 +774,17 @@ public void CopyConfigToDirectory (string directory)
}
}

public bool IsDedupAssembly { get; set; } = false;

public bool IsInterpreted {
get {
return App.IsInterpreted (Identity);
return IsDedupAssembly ? false : App.IsInterpreted (Identity);
}
}

public bool IsAOTCompiled {
get {
return App.IsAOTCompiled (Identity);
return IsDedupAssembly ? true : App.IsAOTCompiled (Identity);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tools/dotnet-linker/Steps/LoadNonSkippedAssembliesStep.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;

using Mono.Cecil;
using Mono.Linker;
Expand Down Expand Up @@ -28,6 +29,7 @@ protected override void TryProcessAssembly (AssemblyDefinition assembly)
case AssemblyAction.Save:
var ad = Configuration.Target.AddAssembly (assembly);
var assemblyFileName = Configuration.GetAssemblyFileName (assembly);
ad.IsDedupAssembly = Path.GetFileName (Configuration.DedupAssembly).Equals (Path.GetFileName (assemblyFileName), StringComparison.OrdinalIgnoreCase);
ad.FullPath = assemblyFileName;
break;
case AssemblyAction.AddBypassNGen: // This should be turned into Save or Delete
Expand Down