xamarin-macios/tools/linker/MonoTouch.Tuner/InlinerSubStep.cs

61 строка
1.7 KiB
C#
Исходник Обычный вид История

[linker] Add an well known candidate inliner substep along with tests (#1513) TL&DR: This is *how* it should be done and tested, it's not complete (single, simple case) nor the most interesting case ;-) The trick is to make sure each case is covered by tests so a mono _bump_ won't give us a BCL that does not conform to what the linker expect. What's the impact ? 1. There is the expected reduction of metadata in mscorlib. Since both methods don't call other API there's no indirect effect (removal). --- before 2017-01-15 11:12:44.000000000 -0500 +++ after 2017-01-15 11:12:56.000000000 -0500 @@ -13166,9 +13166,6 @@ System.Void System.Security.SecurityException::.ctor(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext) System.Void System.Security.SecurityException::.ctor(System.String) System.Void System.Security.SecurityException::GetObjectData(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext) -System.Boolean System.Security.SecurityManager::CheckElevatedPermissions() -System.Security.SecurityManager -System.Void System.Security.SecurityManager::EnsureElevatedPermissions() System.Security.SecurityRulesAttribute System.Security.SecurityRuleSet System.Security.SecurityRulesAttribute::m_ruleSet System.Void System.Security.SecurityRulesAttribute::.ctor(System.Security.SecurityRuleSet) 2. There is no visible size change (even with #1) in mscorlib.dll due to padding (compiler /filealign) mscorlib.dll 793,600 793,600 0 0.00 % 3. there's a *very* small reduction of mscorlib.*.aotdata size mscorlib.armv7.aotdata 717,264 717,216 -48 -0.01 % mscorlib.arm64.aotdata 712,840 712,704 -136 -0.02 % AOT data *.aotdata 6,460,064 6,459,880 -184 0.00 % 4. there's no change in executable size - normal as the AOT compiler has _likely_ already doing the same optimization (before this commit) Executable 29,270,272 29,270,272 0 0.00 % Full comparison: https://gist.github.com/spouliot/0464c8fa3a92b6486dfd90595d9eb718
2017-01-18 05:49:44 +03:00
// Copyright 2016-2017 Xamarin Inc.
using System;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Linker;
using Mono.Tuner;
namespace Xamarin.Linker.Steps {
// This inlining is done, almost exclusively, as a metadata reduction step that
// occurs before linking so some code is not marked (and shipped in final apps).
//
// In many case the AOT'ed native code won't be affected (same size) but the
// *.aotdata files will be smaller. In some cases the AOT compiler does not
// inline some _simple_ cases (cross assemblies) so it can reduce the native
// executable size too (but this is not the step main goal)
public class InlinerSubStep : ExceptionalSubStep {
protected override string Name { get; } = "Inliner";
protected override int ErrorCode { get; } = 2090;
public override SubStepTargets Targets {
get {
return SubStepTargets.Type | SubStepTargets.Method;
}
}
public override bool IsActiveFor (AssemblyDefinition assembly)
{
return Annotations.GetAction (assembly) == AssemblyAction.Link;
}
protected override void Process (MethodDefinition method)
{
if (!method.HasBody)
return;
foreach (var il in method.Body.Instructions) {
if (il.OpCode.Code == Code.Call) {
var mr = il.Operand as MethodReference;
if (mr == null)
continue;
// this removes type System.Security.SecurityManager (unless referenced by user code)
if (!mr.HasParameters && mr.DeclaringType.Is ("System.Security", "SecurityManager")) {
switch (mr.Name) {
case "EnsureElevatedPermissions":
il.OpCode = OpCodes.Nop;
break;
case "CheckElevatedPermissions":
// always positive (no security manager)
il.OpCode = OpCodes.Ldc_I4_1;
break;
}
}
}
}
}
}
}