diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets
index a12429bd6df6..b0b00af71136 100644
--- a/dotnet/targets/Xamarin.Shared.Sdk.targets
+++ b/dotnet/targets/Xamarin.Shared.Sdk.targets
@@ -314,6 +314,14 @@
+
+
+
+
+
+
+
+
<_AssembliesToAOT Include="@(ResolvedFileToPublish)" Condition="'%(Extension)' == '.dll' Or '%(Extension)' == '.exe' " />
@@ -467,6 +475,9 @@
<_CompileNativeExecutableFile Include="@(_RegistrarFile)">
$(_IntermediateNativeLibraryDir)%(Filename).o
+ <_CompileNativeExecutableFile Include="@(_ReferencesFile)">
+ $(_IntermediateNativeLibraryDir)%(Filename).o
+
<_XamarinMainIncludeDirectory Include="$(_XamarinIncludeDirectory)" />
@@ -570,7 +581,7 @@
DylibRPath="$(_DylibRPath)"
EntitlementsInExecutable="$(_CompiledEntitlements)"
Frameworks="@(_NativeExecutableFrameworks);@(_BindingLibraryFrameworks)"
- LinkerFlags="@(_BindingLibraryLinkerFlags);@(_MainLinkerFlags)"
+ LinkerFlags="@(_BindingLibraryLinkerFlags);@(_ReferencesLinkerFlags);@(_MainLinkerFlags)"
LinkWithLibraries="@(_XamarinMainLibraries);@(_BindingLibraryLinkWith);@(_MainLinkWith)"
MinimumOSVersion="$(_MinimumOSVersion)"
ObjectFiles="@(_NativeExecutableObjectFiles)"
diff --git a/tools/dotnet-linker/SetupStep.cs b/tools/dotnet-linker/SetupStep.cs
index 81c3ba450a08..90d36ef2edc9 100644
--- a/tools/dotnet-linker/SetupStep.cs
+++ b/tools/dotnet-linker/SetupStep.cs
@@ -85,10 +85,12 @@ protected override void TryProcess ()
post_sweep_substeps.Add (new RemoveAttributesStep ());
}
+ Steps.Add (new ListExportedSymbols (null));
Steps.Add (new LoadNonSkippedAssembliesStep ());
Steps.Add (new ExtractBindingLibrariesStep ());
Steps.Add (new RegistrarStep ());
Steps.Add (new GenerateMainStep ());
+ Steps.Add (new GenerateReferencesStep ());
Steps.Add (new GatherFrameworksStep ());
Configuration.Write ();
diff --git a/tools/dotnet-linker/Steps/GenerateReferencesStep.cs b/tools/dotnet-linker/Steps/GenerateReferencesStep.cs
new file mode 100644
index 000000000000..fb2ed0ccdd0a
--- /dev/null
+++ b/tools/dotnet-linker/Steps/GenerateReferencesStep.cs
@@ -0,0 +1,48 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+
+using Mono.Cecil;
+
+using Xamarin.Bundler;
+using Xamarin.Linker;
+
+namespace Xamarin {
+
+ public class GenerateReferencesStep : ConfigurationAwareStep {
+ protected override string Name { get; } = "Generate References";
+ protected override int ErrorCode { get; } = 2320;
+
+ protected override void TryEndProcess ()
+ {
+ base.TryEndProcess ();
+
+ var app = Configuration.Application;
+ var required_symbols = Configuration.DerivedLinkContext.RequiredSymbols;
+ var items = new List ();
+
+ switch (app.SymbolMode) {
+ case SymbolMode.Ignore:
+ break;
+ case SymbolMode.Code:
+ string reference_m = Path.Combine (Configuration.CacheDirectory, "reference.m");
+ reference_m = Configuration.Target.GenerateReferencingSource (reference_m, required_symbols);
+ if (!string.IsNullOrEmpty (reference_m)) {
+ var item = new MSBuildItem { Include = reference_m };
+ items.Add (item);
+ }
+ Configuration.WriteOutputForMSBuild ("_ReferencesFile", items);
+ break;
+ case SymbolMode.Linker:
+ foreach (var symbol in required_symbols) {
+ var item = new MSBuildItem { Include = "-u" + symbol.Prefix + symbol.Name };
+ items.Add (item);
+ }
+ Configuration.WriteOutputForMSBuild ("_ReferencesLinkerFlags", items);
+ break;
+ default:
+ throw ErrorHelper.CreateError (99, Errors.MX0099, $"invalid symbol mode: {app.SymbolMode}");
+ }
+ }
+ }
+}
diff --git a/tools/dotnet-linker/dotnet-linker.csproj b/tools/dotnet-linker/dotnet-linker.csproj
index f65498ddf9f3..0eafb100c44d 100644
--- a/tools/dotnet-linker/dotnet-linker.csproj
+++ b/tools/dotnet-linker/dotnet-linker.csproj
@@ -146,6 +146,9 @@
external\tools\linker\MonoTouch.Tuner\Extensions.cs
+
+ external\tools\linker\MonoTouch.Tuner\ListExportedSymbols.cs
+
external\tools\linker\MonoTouch.Tuner\PreserveSmartEnumConversionsSubStep.cs
diff --git a/tools/linker/MonoTouch.Tuner/ListExportedSymbols.cs b/tools/linker/MonoTouch.Tuner/ListExportedSymbols.cs
index 4cbc77599a9d..725153cdac7a 100644
--- a/tools/linker/MonoTouch.Tuner/ListExportedSymbols.cs
+++ b/tools/linker/MonoTouch.Tuner/ListExportedSymbols.cs
@@ -9,8 +9,9 @@
using Xamarin.Bundler;
using Xamarin.Linker;
using Xamarin.Tuner;
+using Xamarin.Utils;
-namespace MonoTouch.Tuner
+namespace Xamarin.Linker.Steps
{
public class ListExportedSymbols : BaseStep
{
@@ -19,7 +20,11 @@ public class ListExportedSymbols : BaseStep
public DerivedLinkContext DerivedLinkContext {
get {
+#if NET
+ return LinkerConfiguration.GetInstance (Context).DerivedLinkContext;
+#else
return (DerivedLinkContext) Context;
+#endif
}
}
@@ -36,8 +41,10 @@ protected override void ProcessAssembly (AssemblyDefinition assembly)
if (Annotations.GetAction (assembly) == AssemblyAction.Delete)
return;
+#if !NET
if (skip_sdk_assemblies && Profile.IsSdkAssembly (assembly))
return;
+#endif
if (!assembly.MainModule.HasTypes)
return;
@@ -116,8 +123,14 @@ void ProcessMethod (MethodDefinition method)
case "__Internal":
DerivedLinkContext.RequiredSymbols.AddFunction (pinfo.EntryPoint).AddMember (method);
break;
- case "System.Native":
+
case "System.Net.Security.Native":
+#if NET
+ if (DerivedLinkContext.App.Platform == ApplePlatform.TVOS)
+ break; // tvOS does not ship with System.Net.Security.Native due to https://github.com/dotnet/runtime/issues/45535
+ goto case "System.Native";
+#endif
+ case "System.Native":
case "System.Security.Cryptography.Native.Apple":
DerivedLinkContext.RequireMonoNative = true;
DerivedLinkContext.RequiredSymbols.AddFunction (pinfo.EntryPoint).AddMember (method);