Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
AppBundleSize: 256,916,796 bytes (250,895.3 KB = 245.0 MB)
AppBundleSize: 256,629,692 bytes (250,614.9 KB = 244.7 MB)
# The following list of files and their sizes is just informational / for review, and isn't used in the test:
Contents/Info.plist:
759 bytes (0.7 KB = 0.0 MB)
743 bytes (0.7 KB = 0.0 MB)
Contents/MacOS/SizeTestApp:
7,404,616 bytes (7,231.1 KB = 7.1 MB)
7,404,248 bytes (7,230.7 KB = 7.1 MB)
Contents/MonoBundle/.xamarin/osx-arm64/_Microsoft.macOS.TypeMap.dll:
4,708,864 bytes (4,598.5 KB = 4.5 MB)
Contents/MonoBundle/.xamarin/osx-arm64/_SizeTestApp.TypeMap.dll:
3,072 bytes (3.0 KB = 0.0 MB)
Contents/MonoBundle/.xamarin/osx-arm64/Microsoft.CSharp.dll:
892,712 bytes (871.8 KB = 0.9 MB)
Contents/MonoBundle/.xamarin/osx-arm64/Microsoft.macOS.dll:
37,003,264 bytes (36,136.0 KB = 35.3 MB)
36,859,904 bytes (35,996.0 KB = 35.2 MB)
Contents/MonoBundle/.xamarin/osx-arm64/Microsoft.VisualBasic.Core.dll:
1,334,568 bytes (1,303.3 KB = 1.3 MB)
Contents/MonoBundle/.xamarin/osx-arm64/Microsoft.VisualBasic.dll:
Expand Down Expand Up @@ -363,7 +363,7 @@ Contents/MonoBundle/.xamarin/osx-x64/_SizeTestApp.TypeMap.dll:
Contents/MonoBundle/.xamarin/osx-x64/Microsoft.CSharp.dll:
795,944 bytes (777.3 KB = 0.8 MB)
Contents/MonoBundle/.xamarin/osx-x64/Microsoft.macOS.dll:
37,003,264 bytes (36,136.0 KB = 35.3 MB)
36,859,904 bytes (35,996.0 KB = 35.2 MB)
Contents/MonoBundle/.xamarin/osx-x64/Microsoft.VisualBasic.Core.dll:
1,166,120 bytes (1,138.8 KB = 1.1 MB)
Contents/MonoBundle/.xamarin/osx-x64/Microsoft.VisualBasic.dll:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
AppBundleSize: 247,542,554 bytes (241,740.8 KB = 236.1 MB)
AppBundleSize: 247,219,818 bytes (241,425.6 KB = 235.8 MB)
# The following list of files and their sizes is just informational / for review, and isn't used in the test:
Contents/Info.plist:
775 bytes (0.8 KB = 0.0 MB)
743 bytes (0.7 KB = 0.0 MB)
Contents/MacOS/SizeTestApp:
8,029,800 bytes (7,841.6 KB = 7.7 MB)
8,029,656 bytes (7,841.5 KB = 7.7 MB)
Contents/MonoBundle/.xamarin/osx-arm64/Microsoft.CSharp.dll:
892,712 bytes (871.8 KB = 0.9 MB)
Contents/MonoBundle/.xamarin/osx-arm64/Microsoft.macOS.dll:
36,715,520 bytes (35,855.0 KB = 35.0 MB)
36,554,240 bytes (35,697.5 KB = 34.9 MB)
Contents/MonoBundle/.xamarin/osx-arm64/Microsoft.VisualBasic.Core.dll:
1,334,568 bytes (1,303.3 KB = 1.3 MB)
Contents/MonoBundle/.xamarin/osx-arm64/Microsoft.VisualBasic.dll:
Expand Down Expand Up @@ -355,7 +355,7 @@ Contents/MonoBundle/.xamarin/osx-arm64/WindowsBase.dll:
Contents/MonoBundle/.xamarin/osx-x64/Microsoft.CSharp.dll:
795,944 bytes (777.3 KB = 0.8 MB)
Contents/MonoBundle/.xamarin/osx-x64/Microsoft.macOS.dll:
36,715,520 bytes (35,855.0 KB = 35.0 MB)
36,554,240 bytes (35,697.5 KB = 34.9 MB)
Contents/MonoBundle/.xamarin/osx-x64/Microsoft.VisualBasic.Core.dll:
1,166,120 bytes (1,138.8 KB = 1.1 MB)
Contents/MonoBundle/.xamarin/osx-x64/Microsoft.VisualBasic.dll:
Expand Down
4 changes: 2 additions & 2 deletions tools/dotnet-linker/AppBundleRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,7 @@ internal bool ImplementConstructNSObjectFactoryMethod (Tuner.DerivedLinkContext
il.Emit (OpCodes.Newobj, ctor);
il.Emit (OpCodes.Ret);

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();

// make sure the trimmer doesn't trim it away if the type is kept
if (context.App.Registrar == RegistrarMode.TrimmableStatic) {
Expand Down Expand Up @@ -2088,7 +2088,7 @@ internal bool ImplementConstructINativeObjectFactoryMethod (Tuner.DerivedLinkCon
throw new UnreachableException ();
}

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();

// make sure the trimmer doesn't trim it away if the type is kept
if (context.App.Registrar == RegistrarMode.TrimmableStatic) {
Expand Down
12 changes: 10 additions & 2 deletions tools/dotnet-linker/CecilExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;

using Xamarin.Bundler;

Expand Down Expand Up @@ -76,8 +77,15 @@ public static MethodBody CreateBody (this MethodDefinition self, out ILProcessor
return body;
}

public static void GenerateILOffsets (this MethodBody body)
// Call this method once a generated method body is complete.
public static void FinalizeGeneratedBody (this MethodBody body)
{
// Use the macro/short form of instructions whenever possible. This makes the generated IL
// smaller, and it also works around a bug in the CoreCLR interpreter, which reads the operand
// of the long form of the ldloc/stloc instructions at the wrong offset (the bug was fixed in
// https://github.com/dotnet/runtime/pull/131547).
body.OptimizeMacros ();

// This does not compute precise offsets, it just assigns a unique number to each instruction
// The trimmer relies on unique offsets to identify instructions
int instructionOffset = 0;
Expand Down Expand Up @@ -164,7 +172,7 @@ public static MethodDefinition AddDefaultConstructor (this TypeDefinition type,
il.Emit (OpCodes.Ldarg_0);
il.Emit (OpCodes.Call, abr.System_Object__ctor);
il.Emit (OpCodes.Ret);
body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
return defaultCtor;
}

Expand Down
12 changes: 12 additions & 0 deletions tools/dotnet-linker/Steps/InlineDlfcnMethodsStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ MethodDefinition GetOrCreateGetNativeFieldMethod (MethodDefinition callingMethod
}
il.Append (il.Create (OpCodes.Ret));

// See the comment in CecilExtensions.FinalizeGeneratedBody for why this is needed.
body.FinalizeGeneratedBody ();

return rv;
}

Expand Down Expand Up @@ -504,6 +507,9 @@ MethodDefinition GetOrCreateSetNativeFieldMethod (MethodDefinition callingMethod
}
il.Append (il.Create (OpCodes.Ret));

// See the comment in CecilExtensions.FinalizeGeneratedBody for why this is needed.
body.FinalizeGeneratedBody ();

return rv;
}

Expand Down Expand Up @@ -558,6 +564,9 @@ MethodDefinition GetOrCreateSetNativeStringMethod (MethodDefinition callingMetho
il.Append (il.Create (OpCodes.Stind_I));
il.Append (il.Create (OpCodes.Ret));

// See the comment in CecilExtensions.FinalizeGeneratedBody for why this is needed.
body.FinalizeGeneratedBody ();

return rv;
}

Expand Down Expand Up @@ -909,6 +918,9 @@ protected override bool ProcessMethod (MethodDefinition method)
il.Append (il.Create (OpCodes.Ldind_I));
il.Append (il.Create (OpCodes.Ret));

// See the comment in CecilExtensions.FinalizeGeneratedBody for why this is needed.
method.Body.FinalizeGeneratedBody ();

modified = true;
return modified; // we replace the whole method body, so no need to continue processing the method
}
Expand Down
16 changes: 8 additions & 8 deletions tools/dotnet-linker/Steps/ManagedRegistrarLookupTablesStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void GenerateLookupTypeId (AssemblyTrampolineInfo infos, TypeDefinition registra
il.Emit (OpCodes.Ldc_I4_M1);
il.Emit (OpCodes.Ret);

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
}

void GenerateLookupType (AssemblyTrampolineInfo infos, TypeDefinition registrarType, List<TypeData> types)
Expand Down Expand Up @@ -331,7 +331,7 @@ void GenerateLookupType (AssemblyTrampolineInfo infos, TypeDefinition registrarT
il.Emit (OpCodes.Ldloc, temporary);
il.Emit (OpCodes.Ret);

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
}

void GenerateConstructNSObject (TypeDefinition registrarType)
Expand Down Expand Up @@ -388,7 +388,7 @@ void GenerateConstructNSObject (TypeDefinition registrarType)
il.Emit (OpCodes.Ldnull);
il.Emit (OpCodes.Ret);

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
}

void GenerateConstructINativeObject (TypeDefinition registrarType)
Expand Down Expand Up @@ -446,7 +446,7 @@ void GenerateConstructINativeObject (TypeDefinition registrarType)
il.Emit (OpCodes.Ldnull);
il.Emit (OpCodes.Ret);

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
}

// We need to preserve the constructor because it might not be used anywhere else.
Expand Down Expand Up @@ -502,7 +502,7 @@ void GenerateRegisterWrapperTypes (TypeDefinition type)

il.Emit (OpCodes.Ret);

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
}

void GenerateLookupUnmanagedFunction (TypeDefinition registrar_type, IList<TrampolineInfo> trampolineInfos)
Expand Down Expand Up @@ -536,7 +536,7 @@ void GenerateLookupUnmanagedFunction (TypeDefinition registrar_type, IList<Tramp
il.Emit (OpCodes.Call, lookupMethods);
}
il.Emit (OpCodes.Ret);
body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
}

// If WrappedLook is true we'll wrap the ldftn instruction in a separate method, which can be useful for debugging,
Expand Down Expand Up @@ -584,7 +584,7 @@ MethodDefinition GenerateLookupMethods (TypeDefinition type, IList<TrampolineInf
var wrappedBody = wrappedLookup.CreateBody (out var wrappedIl);
wrappedIl.Emit (OpCodes.Ldftn, mr);
wrappedIl.Emit (OpCodes.Ret);
wrappedBody.GenerateILOffsets ();
wrappedBody.FinalizeGeneratedBody ();

targets [i] = Instruction.Create (OpCodes.Call, wrappedLookup);
} else {
Expand Down Expand Up @@ -656,7 +656,7 @@ MethodDefinition GenerateLookupMethods (TypeDefinition type, IList<TrampolineInf
il.Emit (OpCodes.Conv_I);
il.Emit (OpCodes.Ret);

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();

return method;
}
Expand Down
10 changes: 5 additions & 5 deletions tools/dotnet-linker/Steps/ManagedRegistrarStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ void EmitGenericReflectionDispatch (MethodDefinition method, MethodDefinition ca
}
il.Emit (OpCodes.Ret);

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
}

// Recursively substitutes generic parameters in a type reference according to the given map.
Expand Down Expand Up @@ -929,7 +929,7 @@ public void EmitCallToProxyMethod (MethodDefinition method, MethodDefinition cal
il.Emit (OpCodes.Callvirt, proxyInterfaceMethod);
il.Emit (OpCodes.Ret);

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
}

public void EmitCallToExportedMethod (MethodDefinition method, MethodDefinition callback)
Expand Down Expand Up @@ -1243,7 +1243,7 @@ public void EmitCallToExportedMethod (MethodDefinition method, MethodDefinition
instr.Operand = leaveTryInstructionOperand;
eh.HandlerEnd = (Instruction) leaveEHInstruction.Operand;

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
}

void AddExceptionHandler (ILProcessor il, VariableDefinition? returnVariable, Instruction placeholderNextInstruction, out ExceptionHandler eh, out Instruction leaveEHInstruction)
Expand Down Expand Up @@ -2039,7 +2039,7 @@ MethodDefinition CloneConstructorWithNativeHandle (MethodDefinition ctor)
il.Emit (OpCodes.Call, ctor);
il.Emit (OpCodes.Ret);

body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();

return clonedCtor;
}
Expand All @@ -2059,7 +2059,7 @@ void ImplementNSObjectRegisterToggleRefMethodStub ()

var body = registerToggleRef!.CreateBody (out var il);
il.Emit (OpCodes.Ret);
body.GenerateILOffsets ();
body.FinalizeGeneratedBody ();
}
}
}
Expand Down
Loading