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>2019-10-26 09:20:15 +0300
committerMarek Safar <marek.safar@gmail.com>2019-12-11 02:05:36 +0300
commit132d8afe7ac5eae64b7597f120319fd2ccca5d5a (patch)
tree195bf01f9ee9602bb0833a941b436576bafbe6c9 /test/Mono.Linker.Tests.Cases/UnreachableBlock/BodiesWithSubstitutions.xml
parentb4770592e35a54823ef5705cc339bf6327229570 (diff)
Add new optimization steps to make Mark step more effective
Two new steps have been introduced BodySubstituterStep This step removes any conditional blocks when the condition or conditions are evaluated as constants. This step does not do any inlining. The conditional logic is kept but based on the known values only one branch is always taken. A simple example which can be detected by linker. ```c# class C { static void Main () { if (Result) Console.WriteLine (); // <- this call will be marked and removed } static bool Result () => false; } ``` RemoveUnreachableBlocksStep A new command-line option called `--substitutions` allow external customization of any methoda for assemblies which are linked. The syntax is same as for existing linker descriptor XML files but it add way to control body modifications. An example of XML file ```xml <linker> <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> <type fullname="Mono.Linker.Tests.Cases.Substitutions.StubBodyWithValue"> <method signature="System.String TestMethod_1()" body="stub" value="abcd"> </method> </type> </assembly> </linker> ``` The `value` attribute is optional and only required when the method stub should not fallback to default behaviour. Additional to `stub` value also `remove` value is supported to forcibly remove body of the method when the method is marked. This is useful when the conditional logic cannot be evaluated by linker and the method will be marked but never actually reached. Applicability Both steps can be combined to achieve the effect of externally customizing which conditional branches can be removed during the linking. I can illustrate that on IntPtr.Size property. With following substitution any code that has compiled in conditional logic for 64 bits handling by checking IntPtr.Size will be removed during linking. ```xml <linker> <assembly fullname="mscorlib"> <type fullname="System.IntPtr"> <method signature="System.Int32 get_Size()" body="stub" value="4"> </method> </type> </assembly> </linker> ``` Implements #752
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/UnreachableBlock/BodiesWithSubstitutions.xml')
-rw-r--r--test/Mono.Linker.Tests.Cases/UnreachableBlock/BodiesWithSubstitutions.xml8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/UnreachableBlock/BodiesWithSubstitutions.xml b/test/Mono.Linker.Tests.Cases/UnreachableBlock/BodiesWithSubstitutions.xml
new file mode 100644
index 000000000..c34957411
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/UnreachableBlock/BodiesWithSubstitutions.xml
@@ -0,0 +1,8 @@
+<linker>
+ <assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
+ <type fullname="Mono.Linker.Tests.Cases.UnreachableBlock.BodiesWithSubstitutions">
+ <method signature="System.Int32 get_Property()" body="stub" value="3">
+ </method>
+ </type>
+ </assembly>
+</linker>