Skip to content

Commit

Permalink
[dotnet-linker] Bump default trampoline count when using the interpre…
Browse files Browse the repository at this point in the history
…ter on x64 in .NET. Fixes #14887. (#15025)

Fixes #14887.
  • Loading branch information
rolfbjarne authored May 18, 2022
1 parent 5c08c5a commit 4c2ddcf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@
<_CustomLinkerOptions>
AreAnyAssembliesTrimmed=$(_AreAnyAssembliesTrimmed)
AssemblyName=$(AssemblyName).dll
@(_AotArguments -> 'AOTArgument=%(Identity)')
AOTCompiler=$(_AOTCompiler)
AOTOutputDirectory=$(_AOTOutputDirectory)
AppBundleManifestPath=$(_AppBundleManifestPath)
Expand Down Expand Up @@ -996,7 +997,6 @@
<AOTCompile
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
AotArguments="@(_AotArguments)"
Assemblies="@(_AssembliesToAOT)"
AOTCompilerPath="$(_AOTCompiler)"
InputDirectory="$(_AOTInputDirectory)"
Expand Down
30 changes: 30 additions & 0 deletions tools/common/Application.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -1606,6 +1607,35 @@ public void GetAotArguments (string filename, Abi abi, string outputDir, string
aotArguments.Add ($"outfile={outputFile}");
if (enable_llvm)
aotArguments.Add ($"llvm-outfile={llvmOutputFile}");

#if NET
// If the interpreter is enabled, and we're building for x86_64, we're AOT-compiling but we
// don't have access to infinite trampolines. So we're bumping the trampoline count (unless
// the developer has already set a value) to something higher than the default.
//
// Ref:
// * https://github.com/xamarin/xamarin-macios/issues/14887
// * https://github.com/dotnet/runtime/issues/68808
if (interp && (abi & Abi.x86_64) == Abi.x86_64) {
// The default values are here: https://github.com/dotnet/runtime/blob/main/src/mono/mono/mini/aot-compiler.c#L13945-L13953
// Let's try 4x the default values.
var trampolines = new []
{
(Name: "ntrampolines", Default: 4096),
(Name: "nrgctx-trampolines", Default: 4096),
(Name: "nimt-trampolines", Default: 512),
(Name: "nrgctx-fetch-trampolines", Default: 128),
(Name: "ngsharedvt-trampolines", Default: 512),
(Name: "nftnptr-arg-trampolines", Default: 128),
(Name: "nunbox-arbitrary-trampolines", Default: 256),
};
foreach (var tramp in trampolines) {
var nameWithEq = tramp.Name + "=";
if (!aotArguments.Any (v => v.StartsWith (nameWithEq, StringComparison.Ordinal)))
aotArguments.Add (nameWithEq + (tramp.Default * 4).ToString (CultureInfo.InvariantCulture));
}
}
#endif
}

public string AssemblyName {
Expand Down
5 changes: 5 additions & 0 deletions tools/dotnet-linker/LinkerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public static LinkerConfiguration GetInstance (LinkContext context, bool createI
// This is the AssemblyName MSBuild property for the main project (which is also the root/entry assembly)
Application.RootAssemblies.Add (value);
break;
case "AOTArgument":
if (!string.IsNullOrEmpty (value))
Application.AotArguments.Add (value);
break;
case "AOTCompiler":
AOTCompiler = value;
break;
Expand Down Expand Up @@ -380,6 +384,7 @@ public void Write ()
if (Verbosity > 0) {
Console.WriteLine ($"LinkerConfiguration:");
Console.WriteLine ($" ABIs: {string.Join (", ", Abis.Select (v => v.AsArchString ()))}");
Console.WriteLine ($" AOTArguments: {string.Join (", ", Application.AotArguments)}");
Console.WriteLine ($" AOTOutputDirectory: {AOTOutputDirectory}");
Console.WriteLine ($" AppBundleManifestPath: {Application.InfoPListPath}");
Console.WriteLine ($" AreAnyAssembliesTrimmed: {Application.AreAnyAssembliesTrimmed}");
Expand Down

5 comments on commit 4c2ddcf

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

💻 [CI Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: 4c2ddcf3497b4f7c662055786300fffcea8ac805

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

📋 [CI Build] API Diff 📋

API diff (for current PR)

ℹ️ API Diff (from PR only) (please review changes)

API diff: vsdrops gist

Xamarin
.NET
Xamarin vs .NET
iOS vs Mac Catalyst (.NET)

API diff (vs stable)

✅ API Diff from stable

API diff: vsdrops gist

Xamarin
.NET
Xamarin vs .NET
iOS vs Mac Catalyst (.NET)

Generator diff

Generator Diff (no change)

Pipeline on Agent XAMMINI-054.Monterey'
Hash: 4c2ddcf3497b4f7c662055786300fffcea8ac805

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

💻 [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: 4c2ddcf3497b4f7c662055786300fffcea8ac805

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

📚 [CI Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMMINI-055.Monterey
Hash: 4c2ddcf3497b4f7c662055786300fffcea8ac805

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

✅ [CI Build] Tests passed on VSTS: simulator tests iOS. ✅

Tests passed on VSTS: simulator tests iOS.

🎉 All 234 tests passed 🎉

Pipeline on Agent XAMBOT-1043.Monterey'
[dotnet-linker] Bump default trampoline count when using the interpreter on x64 in .NET. Fixes #14887. (#15025)

Please sign in to comment.