Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2022-01-06 15:33:04 +0300
committerMarek Safar <marek.safar@gmail.com>2022-01-06 15:33:04 +0300
commitb506676ef4a97e0813a6d8636e0554945d82b852 (patch)
treebd4903b248c1cd14831536bc009adbedfd384e83
parent581b5b182534f0a916b1d2f9032584f29e3f0b29 (diff)
-rw-r--r--src/linker/Linker.Steps/SweepStep.cs77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/linker/Linker.Steps/SweepStep.cs b/src/linker/Linker.Steps/SweepStep.cs
index c560d4e13..56c4677bc 100644
--- a/src/linker/Linker.Steps/SweepStep.cs
+++ b/src/linker/Linker.Steps/SweepStep.cs
@@ -455,6 +455,9 @@ namespace Mono.Linker.Steps
bool sweepNames = CanSweepNamesForMember (method, MetadataTrimming.ParameterName);
+ if (method.HasBody && sweepNames)
+ RemoveParameterNamesReferences (method);
+
foreach (var parameter in method.Parameters) {
if (sweepNames)
parameter.Name = null;
@@ -464,6 +467,80 @@ namespace Mono.Linker.Steps
}
}
+ static void RemoveParameterNamesReferences (MethodDefinition method)
+ {
+ var instructions = method.Body.Instructions;
+ for (int i = 1; i < instructions.Count; ++i) {
+ Instruction instr = instructions [i];
+ if (instr.OpCode.Code != Code.Ldstr)
+ continue;
+
+ //
+ // The patterns we are looking for are like
+ //
+ // ldstr "argument"
+ // newobj instance void System.ArgumentNullException::.ctor(string)
+ //
+ // OR
+ //
+ // ldstr "argument"
+ // ldstr "another string"
+ // newobj instance void System.ArgumentNullException::.ctor(string, string)
+ //
+ // OR
+ //
+ // ldstr "argument"
+ // call string System.SR::get_ArgumentOutOfRange_StartIndex()
+ // newobj instance void System.ArgumentOutOfRangeException::.ctor(string, string)
+ //
+ // OR
+ //
+ // ldstr "argument"
+ // newobj instance void System.ArgumentException::.ctor(string, string)
+ //
+ string str = (string)instr.Operand;
+ int index = FindParameterIndex (method, str);
+ if (index == 0)
+ continue;
+
+ //if (!IsSingleArgumentExceptionCtor (instructions, i))
+ // continue;
+
+ //instr.Operand = "#" + index;
+ }
+/*
+ static bool IsArgumentExceptionCtor (Collection<Instruction> instructions, int index)
+ {
+ for (int peek = 0; index < instructions.Count && peek < 2; ++peek) {
+ switch (instructions [index + peek].OpCode.Code) {
+ case Code.Newobj:
+ if (instructions [index + peek].Operand is not MethodReference mr)
+ continue;
+
+ Console.WriteLine (mr);
+ return true;
+ case Code.Ldstr:
+ continue;
+ }
+
+ return false;
+ }
+
+ return false;
+ }
+*/
+ static int FindParameterIndex (MethodDefinition method, string value)
+ {
+ var p = method.Parameters;
+ for (int i = 0; i < p.Count; ++i) {
+ if (p[i].Name == value)
+ return i + 1;
+ }
+
+ return 0;
+ }
+ }
+
void SweepDebugInfo (Collection<MethodDefinition> methods)
{
List<ScopeDebugInformation>? sweptScopes = null;