Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet-linker] Bump default trampoline count when using the interpreter on x64 in .NET. Fixes #14887. #15025

Merged
merged 4 commits into from
May 18, 2022
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
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