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
16 changes: 16 additions & 0 deletions tools/dotnet-linker/Compat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ public class Pipeline {
}
}

namespace Xamarin.Linker {
public class Profile {
public LinkerConfiguration Configuration { get; private set; }

public Profile (LinkerConfiguration config)
{
Configuration = config;
}

public bool IsProductAssembly (AssemblyDefinition assembly)
{
return assembly.Name.Name == Configuration.PlatformAssembly;
}
}
}

namespace Mono.Linker {
public static class LinkContextExtensions {
public static void LogMessage (this LinkContext context, string messsage)
Expand Down
3 changes: 3 additions & 0 deletions tools/dotnet-linker/LinkerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

using Xamarin.Bundler;
using Xamarin.Utils;
using Xamarin.Tuner;

using ObjCRuntime;

Expand Down Expand Up @@ -38,6 +39,7 @@ public class LinkerConfiguration {
public CompilerFlags CompilerFlags;

public LinkContext Context { get; private set; }
public Profile Profile { get; private set; }

// The list of assemblies is populated in CollectAssembliesStep.
public List<AssemblyDefinition> Assemblies = new List<AssemblyDefinition> ();
Expand All @@ -62,6 +64,7 @@ public static LinkerConfiguration GetInstance (LinkContext context)
if (!File.Exists (linker_file))
throw new FileNotFoundException ($"The custom linker file {linker_file} does not exist.");

Profile = new Profile (this);
Application = new Application (this);
Target = new Target (Application);
CompilerFlags = new CompilerFlags (Target);
Expand Down
1 change: 1 addition & 0 deletions tools/dotnet-linker/SetupStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected override void Process ()
// [assembly: LinkSafe] attributes, which means we treat them as sdk assemblies and those may have
// Preserve attributes.
prelink_substeps.Add (new ApplyPreserveAttribute ());
prelink_substeps.Add (new PreserveSmartEnumConversionsSubStep ());
}

Steps.Add (new LoadNonSkippedAssembliesStep ());
Expand Down
6 changes: 6 additions & 0 deletions tools/dotnet-linker/dotnet-linker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,15 @@
<Compile Include="..\linker\ApplyPreserveAttribute.cs">
<Link>external\tools\linker\ApplyPreserveAttribute.cs</Link>
</Compile>
<Compile Include="..\linker\ExceptionalSubStep.cs">
<Link>external\tools\linker\ExceptionalSubStep.cs</Link>
</Compile>
<Compile Include="..\linker\MonoTouch.Tuner\Extensions.cs">
<Link>external\tools\linker\MonoTouch.Tuner\Extensions.cs</Link>
</Compile>
<Compile Include="..\linker\MonoTouch.Tuner\PreserveSmartEnumConversionsSubStep.cs">
<Link>external\tools\linker\MonoTouch.Tuner\PreserveSmartEnumConversionsSubStep.cs</Link>
</Compile>
<Compile Include="..\linker\MobileExtensions.cs">
<Link>external\tools\linker\MobileExtensions.cs</Link>
</Compile>
Expand Down
25 changes: 25 additions & 0 deletions tools/linker/ExceptionalSubStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,40 @@

using Xamarin.Tuner;

#if NET
using Mono.Linker;
using Mono.Linker.Steps;
#endif

namespace Xamarin.Linker {

public abstract class ExceptionalSubStep : BaseSubStep {

protected DerivedLinkContext LinkContext {
get {
#if NET
throw new NotImplementedException ();
#else
return (DerivedLinkContext) base.context;
#endif
}
}

#if NET
protected LinkContext context {
get { return Context; }
}

protected LinkerConfiguration Configuration {
get { return LinkerConfiguration.GetInstance (Context); }
}

protected Profile Profile {
get {
return Configuration.Profile;
}
}
#endif

public override sealed void ProcessAssembly (AssemblyDefinition assembly)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
using Mono.Cecil.Cil;
using Mono.Linker;
using Mono.Tuner;
#if NET
using Mono.Linker.Steps;
#else
using MonoTouch.Tuner;
#endif

using Xamarin.Bundler;

Expand All @@ -21,7 +25,10 @@ public class PreserveSmartEnumConversionsSubStep : ExceptionalSubStep

public override SubStepTargets Targets {
get {
return SubStepTargets.Method | SubStepTargets.Property;
return
SubStepTargets.Method
| SubStepTargets.Type // SubStepTargets.Type is only needed to work around a linker bug: https://github.com/mono/linker/issues/1458
| SubStepTargets.Property;
}
}

Expand All @@ -41,6 +48,18 @@ public override bool IsActiveFor (AssemblyDefinition assembly)

void Preserve (Tuple<MethodDefinition, MethodDefinition> pair, MethodDefinition conditionA, MethodDefinition conditionB = null)
{
#if NET
// The AddPreservedMethod (MethodDefinition, MethodDefinition) has not been exposed yet, so preserve the entire containing type instead.
// https://github.com/mono/linker/issues/1456
if (conditionA != null) {
context.Annotations.AddPreservedMethod (conditionA.DeclaringType, pair.Item1);
context.Annotations.AddPreservedMethod (conditionA.DeclaringType, pair.Item2);
}
if (conditionB != null) {
context.Annotations.AddPreservedMethod (conditionB.DeclaringType, pair.Item1);
context.Annotations.AddPreservedMethod (conditionB.DeclaringType, pair.Item2);
}
#else
if (conditionA != null) {
context.Annotations.AddPreservedMethod (conditionA, pair.Item1);
context.Annotations.AddPreservedMethod (conditionA, pair.Item2);
Expand All @@ -49,6 +68,7 @@ void Preserve (Tuple<MethodDefinition, MethodDefinition> pair, MethodDefinition
context.Annotations.AddPreservedMethod (conditionB, pair.Item1);
context.Annotations.AddPreservedMethod (conditionB, pair.Item2);
}
#endif
}

void ProcessAttributeProvider (ICustomAttributeProvider provider, MethodDefinition conditionA, MethodDefinition conditionB = null)
Expand Down