Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit reflection usage in our assemblies #4708

Closed
radekdoulik opened this issue May 21, 2020 · 2 comments
Closed

Audit reflection usage in our assemblies #4708

radekdoulik opened this issue May 21, 2020 · 2 comments
Assignees
Milestone

Comments

@radekdoulik
Copy link
Member

The ILlink is now doing reflection analysis resulting in reported warnings. Context: https://github.com/mono/linker/blob/master/docs/design/reflection-flow.md

We should audit our reflection usage by checking the reported warnings and look into how to solve these. (by updating the code where needed or suppressing the warnings)

Example output:

...
                     ILlinker : Unrecognized reflection pattern warning IL2006: Reflection call 'System.Type System.Type::GetType(System.String,System.Func`2<System.Reflection.AssemblyName,System.Reflection.Assembly>,System.Func`4<System.Reflection.Assembly,System.String,System.Boolean,System.Type>,System.Boolean,System.Boolean,System.Threading.StackCrawlMark&)' inside 'System.Type System.Type::GetType(System.String,System.Func`2<System.Reflection.AssemblyName,System.Reflection.Assembly>,System.Func`4<System.Reflection.Assembly,System.String,System.Boolean,System.Type>,System.Boolean)' was detected with unknown value for the type name. [/Users/runner/runners/2.168.2/work/1/s/bin/TestRelease/temp/DotNetBuildandroid.21-armTrue/UnnamedProject.csproj]
                     ILlinker : Unrecognized reflection pattern warning IL2006: The parameter 'nullableType' of method 'System.Void System.Linq.Expressions.Compiler.ILGen::EmitGetValue(System.Reflection.Emit.ILGenerator,System.Type)' with dynamically accessed member kinds 'None' is passed into the parameter '' of method 'System.Reflection.MethodInfo System.Type::GetMethod(System.String,System.Reflection.BindingFlags)' which requires dynamically accessed member kinds 'PublicMethods'. To fix this add DynamicallyAccessedMembersAttribute to it and specify at least these member kinds 'PublicMethods'. [/Users/runner/runners/2.168.2/work/1/s/bin/TestRelease/temp/DotNetBuildandroid.21-armTrue/UnnamedProject.csproj]

    115 Warning(s)
    0 Error(s)
@radekdoulik radekdoulik added this to the .net-5 milestone May 21, 2020
@radekdoulik radekdoulik self-assigned this May 21, 2020
radekdoulik added a commit that referenced this issue May 21, 2020
This can be enabled again when #4708
is resolved.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue May 26, 2020
Squashed commit of the following:

commit fce7a06
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 26 15:36:50 2020 +0200

    Additional packages for XForms 4.5 on NET5

    To make the test build with linker

commit f7cce5a
Merge: 466ac45 f3bf582
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:37:13 2020 +0200

    Merge branch 'master' into net5-linker

commit 466ac45
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:22:12 2020 +0200

    Add missing EndProject

    Which fell out in previous merge

commit 324e269
Merge: 759622c 3c868e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:59:09 2020 +0200

    Merge branch 'master' into net5-linker

commit 759622c
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:52:17 2020 +0200

    Do not require 0 warning for Release

    This can be enabled again when dotnet#4708
    is resolved.

commit 42ba7a2
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 20 16:29:51 2020 +0200

    Add Xamarin.Android.Linker.csproj to solution

    So that it is built

commit 03550e4
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 19 19:09:08 2020 +0200

    Set output path to the location used for nuget

commit cb80cad
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:51:48 2020 +0200

    One more `using Mono.Tuner;` missing.

commit ddfcc1f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:22:25 2020 +0200

    One more white space restore

commit 06cc5ee
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:20:41 2020 +0200

    Restore the white space

commit 915d90b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:14:39 2020 +0200

    Removed a bit too much

    We still need `using Mono.Tuner;` for non NET5 version.

commit 3bafcc9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Fri May 15 17:54:39 2020 +0200

    Get rid of some of the #if's

    We don't need them anymore as we have the new extension method in that
    namespace

commit 3a0f853
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:13:36 2020 +0200

    Set `MonoAndroidHelper.TargetFrameworkDirectories`

commit 9b5497f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:10:45 2020 +0200

    Put the extension in Mono.Linker namespace

    To avoid using Xamarin.Android.Linker namespace and introducing another
    `#if`'s

commit 6aae5e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:48:44 2020 +0200

    Add LinkContext.LogMessage extension method

    To avoid few #if's and make the code better readable

commit 340d7e9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:28:59 2020 +0200

    Add proguard/r8 support

commit 45c6574
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:15:46 2020 +0200

    Remove old comment

commit c396bec
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:13:48 2020 +0200

    Remove debug message

commit 029b6e6
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:36:34 2020 +0200

    Clean old notes

commit 1cc7e6e
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:16:02 2020 +0200

    Use the substeps, set the linker output directory

    And re-enable `_RemoveRegisterAttribute` target, as the assemblies now
    end up in the right place

commit e61230f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 12:56:40 2020 +0200

    Build more steps for net5

commit 9ee06d1
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:15:04 2020 +0200

    Run ILLink with our custom SetupStep

    The step so far only installs `FixAbstractMethodsStep`.

    Parts of the code come from xamarin-macios repo. We might share these
    and move them to linker. Or enable more linker API to avoid getting
    the pipeline steps with reflection.

commit 573f854
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:09:21 2020 +0200

    Enable linker on NET5

    Do not run `LinkAssemblies` task on NET5

    Temporarily disable `_RemoveRegisterAttribute` target. It is crashing,
    presumably because the assemblies are in different location.

commit 3df24dc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu Apr 30 16:22:21 2020 +0200

    Add Xamarin.Android.Linker Profile class

    And use it in place of Mono.Tuner one, where needed for net5

commit d6acfe5
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:35:28 2020 +0200

    Use new Context.GetLoadedAssembly on net5

commit 572fa0b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:19:12 2020 +0200

    Use newer linker log API on net5

commit 9cb64f7
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:42 2020 +0200

    Do not check for AppDomain usage on net5

commit 50e4fcc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:01 2020 +0200

    Do not use Mono.Tuner sources in net5 linker

commit 49de381
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:02:47 2020 +0200

    Use the new linker logging iface (conditionaly)

commit 47ad67d
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:01:50 2020 +0200

    Use newer illink nuget

commit b4f6f5c
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Mon Apr 6 21:26:35 2020 -0500

    #if around usage of SafeReadSymbols

commit dbea5d5
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Fri Apr 3 11:10:16 2020 -0500

    [Xamarin.Android.Linker] exploring the new .NET linker

    Based on the new `Microsoft.NET.ILLink` NuGet package, this is a start
    to what it would look like to use it for Xamarin.Android.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue May 27, 2020
Squashed commit of the following:

commit fce7a06
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 26 15:36:50 2020 +0200

    Additional packages for XForms 4.5 on NET5

    To make the test build with linker

commit f7cce5a
Merge: 466ac45 f3bf582
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:37:13 2020 +0200

    Merge branch 'master' into net5-linker

commit 466ac45
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:22:12 2020 +0200

    Add missing EndProject

    Which fell out in previous merge

commit 324e269
Merge: 759622c 3c868e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:59:09 2020 +0200

    Merge branch 'master' into net5-linker

commit 759622c
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:52:17 2020 +0200

    Do not require 0 warning for Release

    This can be enabled again when dotnet#4708
    is resolved.

commit 42ba7a2
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 20 16:29:51 2020 +0200

    Add Xamarin.Android.Linker.csproj to solution

    So that it is built

commit 03550e4
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 19 19:09:08 2020 +0200

    Set output path to the location used for nuget

commit cb80cad
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:51:48 2020 +0200

    One more `using Mono.Tuner;` missing.

commit ddfcc1f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:22:25 2020 +0200

    One more white space restore

commit 06cc5ee
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:20:41 2020 +0200

    Restore the white space

commit 915d90b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:14:39 2020 +0200

    Removed a bit too much

    We still need `using Mono.Tuner;` for non NET5 version.

commit 3bafcc9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Fri May 15 17:54:39 2020 +0200

    Get rid of some of the #if's

    We don't need them anymore as we have the new extension method in that
    namespace

commit 3a0f853
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:13:36 2020 +0200

    Set `MonoAndroidHelper.TargetFrameworkDirectories`

commit 9b5497f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:10:45 2020 +0200

    Put the extension in Mono.Linker namespace

    To avoid using Xamarin.Android.Linker namespace and introducing another
    `#if`'s

commit 6aae5e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:48:44 2020 +0200

    Add LinkContext.LogMessage extension method

    To avoid few #if's and make the code better readable

commit 340d7e9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:28:59 2020 +0200

    Add proguard/r8 support

commit 45c6574
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:15:46 2020 +0200

    Remove old comment

commit c396bec
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:13:48 2020 +0200

    Remove debug message

commit 029b6e6
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:36:34 2020 +0200

    Clean old notes

commit 1cc7e6e
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:16:02 2020 +0200

    Use the substeps, set the linker output directory

    And re-enable `_RemoveRegisterAttribute` target, as the assemblies now
    end up in the right place

commit e61230f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 12:56:40 2020 +0200

    Build more steps for net5

commit 9ee06d1
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:15:04 2020 +0200

    Run ILLink with our custom SetupStep

    The step so far only installs `FixAbstractMethodsStep`.

    Parts of the code come from xamarin-macios repo. We might share these
    and move them to linker. Or enable more linker API to avoid getting
    the pipeline steps with reflection.

commit 573f854
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:09:21 2020 +0200

    Enable linker on NET5

    Do not run `LinkAssemblies` task on NET5

    Temporarily disable `_RemoveRegisterAttribute` target. It is crashing,
    presumably because the assemblies are in different location.

commit 3df24dc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu Apr 30 16:22:21 2020 +0200

    Add Xamarin.Android.Linker Profile class

    And use it in place of Mono.Tuner one, where needed for net5

commit d6acfe5
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:35:28 2020 +0200

    Use new Context.GetLoadedAssembly on net5

commit 572fa0b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:19:12 2020 +0200

    Use newer linker log API on net5

commit 9cb64f7
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:42 2020 +0200

    Do not check for AppDomain usage on net5

commit 50e4fcc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:01 2020 +0200

    Do not use Mono.Tuner sources in net5 linker

commit 49de381
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:02:47 2020 +0200

    Use the new linker logging iface (conditionaly)

commit 47ad67d
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:01:50 2020 +0200

    Use newer illink nuget

commit b4f6f5c
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Mon Apr 6 21:26:35 2020 -0500

    #if around usage of SafeReadSymbols

commit dbea5d5
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Fri Apr 3 11:10:16 2020 -0500

    [Xamarin.Android.Linker] exploring the new .NET linker

    Based on the new `Microsoft.NET.ILLink` NuGet package, this is a start
    to what it would look like to use it for Xamarin.Android.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue May 27, 2020
Squashed commit of the following:

commit fce7a06
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 26 15:36:50 2020 +0200

    Additional packages for XForms 4.5 on NET5

    To make the test build with linker

commit f7cce5a
Merge: 466ac45 f3bf582
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:37:13 2020 +0200

    Merge branch 'master' into net5-linker

commit 466ac45
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:22:12 2020 +0200

    Add missing EndProject

    Which fell out in previous merge

commit 324e269
Merge: 759622c 3c868e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:59:09 2020 +0200

    Merge branch 'master' into net5-linker

commit 759622c
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:52:17 2020 +0200

    Do not require 0 warning for Release

    This can be enabled again when dotnet#4708
    is resolved.

commit 42ba7a2
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 20 16:29:51 2020 +0200

    Add Xamarin.Android.Linker.csproj to solution

    So that it is built

commit 03550e4
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 19 19:09:08 2020 +0200

    Set output path to the location used for nuget

commit cb80cad
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:51:48 2020 +0200

    One more `using Mono.Tuner;` missing.

commit ddfcc1f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:22:25 2020 +0200

    One more white space restore

commit 06cc5ee
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:20:41 2020 +0200

    Restore the white space

commit 915d90b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:14:39 2020 +0200

    Removed a bit too much

    We still need `using Mono.Tuner;` for non NET5 version.

commit 3bafcc9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Fri May 15 17:54:39 2020 +0200

    Get rid of some of the #if's

    We don't need them anymore as we have the new extension method in that
    namespace

commit 3a0f853
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:13:36 2020 +0200

    Set `MonoAndroidHelper.TargetFrameworkDirectories`

commit 9b5497f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:10:45 2020 +0200

    Put the extension in Mono.Linker namespace

    To avoid using Xamarin.Android.Linker namespace and introducing another
    `#if`'s

commit 6aae5e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:48:44 2020 +0200

    Add LinkContext.LogMessage extension method

    To avoid few #if's and make the code better readable

commit 340d7e9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:28:59 2020 +0200

    Add proguard/r8 support

commit 45c6574
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:15:46 2020 +0200

    Remove old comment

commit c396bec
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:13:48 2020 +0200

    Remove debug message

commit 029b6e6
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:36:34 2020 +0200

    Clean old notes

commit 1cc7e6e
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:16:02 2020 +0200

    Use the substeps, set the linker output directory

    And re-enable `_RemoveRegisterAttribute` target, as the assemblies now
    end up in the right place

commit e61230f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 12:56:40 2020 +0200

    Build more steps for net5

commit 9ee06d1
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:15:04 2020 +0200

    Run ILLink with our custom SetupStep

    The step so far only installs `FixAbstractMethodsStep`.

    Parts of the code come from xamarin-macios repo. We might share these
    and move them to linker. Or enable more linker API to avoid getting
    the pipeline steps with reflection.

commit 573f854
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:09:21 2020 +0200

    Enable linker on NET5

    Do not run `LinkAssemblies` task on NET5

    Temporarily disable `_RemoveRegisterAttribute` target. It is crashing,
    presumably because the assemblies are in different location.

commit 3df24dc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu Apr 30 16:22:21 2020 +0200

    Add Xamarin.Android.Linker Profile class

    And use it in place of Mono.Tuner one, where needed for net5

commit d6acfe5
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:35:28 2020 +0200

    Use new Context.GetLoadedAssembly on net5

commit 572fa0b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:19:12 2020 +0200

    Use newer linker log API on net5

commit 9cb64f7
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:42 2020 +0200

    Do not check for AppDomain usage on net5

commit 50e4fcc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:01 2020 +0200

    Do not use Mono.Tuner sources in net5 linker

commit 49de381
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:02:47 2020 +0200

    Use the new linker logging iface (conditionaly)

commit 47ad67d
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:01:50 2020 +0200

    Use newer illink nuget

commit b4f6f5c
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Mon Apr 6 21:26:35 2020 -0500

    #if around usage of SafeReadSymbols

commit dbea5d5
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Fri Apr 3 11:10:16 2020 -0500

    [Xamarin.Android.Linker] exploring the new .NET linker

    Based on the new `Microsoft.NET.ILLink` NuGet package, this is a start
    to what it would look like to use it for Xamarin.Android.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue May 29, 2020
Squashed commit of the following:

commit fce7a06
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 26 15:36:50 2020 +0200

    Additional packages for XForms 4.5 on NET5

    To make the test build with linker

commit f7cce5a
Merge: 466ac45 f3bf582
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:37:13 2020 +0200

    Merge branch 'master' into net5-linker

commit 466ac45
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:22:12 2020 +0200

    Add missing EndProject

    Which fell out in previous merge

commit 324e269
Merge: 759622c 3c868e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:59:09 2020 +0200

    Merge branch 'master' into net5-linker

commit 759622c
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:52:17 2020 +0200

    Do not require 0 warning for Release

    This can be enabled again when dotnet#4708
    is resolved.

commit 42ba7a2
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 20 16:29:51 2020 +0200

    Add Xamarin.Android.Linker.csproj to solution

    So that it is built

commit 03550e4
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 19 19:09:08 2020 +0200

    Set output path to the location used for nuget

commit cb80cad
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:51:48 2020 +0200

    One more `using Mono.Tuner;` missing.

commit ddfcc1f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:22:25 2020 +0200

    One more white space restore

commit 06cc5ee
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:20:41 2020 +0200

    Restore the white space

commit 915d90b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:14:39 2020 +0200

    Removed a bit too much

    We still need `using Mono.Tuner;` for non NET5 version.

commit 3bafcc9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Fri May 15 17:54:39 2020 +0200

    Get rid of some of the #if's

    We don't need them anymore as we have the new extension method in that
    namespace

commit 3a0f853
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:13:36 2020 +0200

    Set `MonoAndroidHelper.TargetFrameworkDirectories`

commit 9b5497f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:10:45 2020 +0200

    Put the extension in Mono.Linker namespace

    To avoid using Xamarin.Android.Linker namespace and introducing another
    `#if`'s

commit 6aae5e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:48:44 2020 +0200

    Add LinkContext.LogMessage extension method

    To avoid few #if's and make the code better readable

commit 340d7e9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:28:59 2020 +0200

    Add proguard/r8 support

commit 45c6574
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:15:46 2020 +0200

    Remove old comment

commit c396bec
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:13:48 2020 +0200

    Remove debug message

commit 029b6e6
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:36:34 2020 +0200

    Clean old notes

commit 1cc7e6e
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:16:02 2020 +0200

    Use the substeps, set the linker output directory

    And re-enable `_RemoveRegisterAttribute` target, as the assemblies now
    end up in the right place

commit e61230f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 12:56:40 2020 +0200

    Build more steps for net5

commit 9ee06d1
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:15:04 2020 +0200

    Run ILLink with our custom SetupStep

    The step so far only installs `FixAbstractMethodsStep`.

    Parts of the code come from xamarin-macios repo. We might share these
    and move them to linker. Or enable more linker API to avoid getting
    the pipeline steps with reflection.

commit 573f854
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:09:21 2020 +0200

    Enable linker on NET5

    Do not run `LinkAssemblies` task on NET5

    Temporarily disable `_RemoveRegisterAttribute` target. It is crashing,
    presumably because the assemblies are in different location.

commit 3df24dc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu Apr 30 16:22:21 2020 +0200

    Add Xamarin.Android.Linker Profile class

    And use it in place of Mono.Tuner one, where needed for net5

commit d6acfe5
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:35:28 2020 +0200

    Use new Context.GetLoadedAssembly on net5

commit 572fa0b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:19:12 2020 +0200

    Use newer linker log API on net5

commit 9cb64f7
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:42 2020 +0200

    Do not check for AppDomain usage on net5

commit 50e4fcc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:01 2020 +0200

    Do not use Mono.Tuner sources in net5 linker

commit 49de381
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:02:47 2020 +0200

    Use the new linker logging iface (conditionaly)

commit 47ad67d
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:01:50 2020 +0200

    Use newer illink nuget

commit b4f6f5c
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Mon Apr 6 21:26:35 2020 -0500

    #if around usage of SafeReadSymbols

commit dbea5d5
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Fri Apr 3 11:10:16 2020 -0500

    [Xamarin.Android.Linker] exploring the new .NET linker

    Based on the new `Microsoft.NET.ILLink` NuGet package, this is a start
    to what it would look like to use it for Xamarin.Android.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jun 1, 2020
Squashed commit of the following:

commit fce7a06
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 26 15:36:50 2020 +0200

    Additional packages for XForms 4.5 on NET5

    To make the test build with linker

commit f7cce5a
Merge: 466ac45 f3bf582
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:37:13 2020 +0200

    Merge branch 'master' into net5-linker

commit 466ac45
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:22:12 2020 +0200

    Add missing EndProject

    Which fell out in previous merge

commit 324e269
Merge: 759622c 3c868e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:59:09 2020 +0200

    Merge branch 'master' into net5-linker

commit 759622c
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:52:17 2020 +0200

    Do not require 0 warning for Release

    This can be enabled again when dotnet#4708
    is resolved.

commit 42ba7a2
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 20 16:29:51 2020 +0200

    Add Xamarin.Android.Linker.csproj to solution

    So that it is built

commit 03550e4
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 19 19:09:08 2020 +0200

    Set output path to the location used for nuget

commit cb80cad
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:51:48 2020 +0200

    One more `using Mono.Tuner;` missing.

commit ddfcc1f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:22:25 2020 +0200

    One more white space restore

commit 06cc5ee
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:20:41 2020 +0200

    Restore the white space

commit 915d90b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:14:39 2020 +0200

    Removed a bit too much

    We still need `using Mono.Tuner;` for non NET5 version.

commit 3bafcc9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Fri May 15 17:54:39 2020 +0200

    Get rid of some of the #if's

    We don't need them anymore as we have the new extension method in that
    namespace

commit 3a0f853
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:13:36 2020 +0200

    Set `MonoAndroidHelper.TargetFrameworkDirectories`

commit 9b5497f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:10:45 2020 +0200

    Put the extension in Mono.Linker namespace

    To avoid using Xamarin.Android.Linker namespace and introducing another
    `#if`'s

commit 6aae5e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:48:44 2020 +0200

    Add LinkContext.LogMessage extension method

    To avoid few #if's and make the code better readable

commit 340d7e9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:28:59 2020 +0200

    Add proguard/r8 support

commit 45c6574
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:15:46 2020 +0200

    Remove old comment

commit c396bec
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:13:48 2020 +0200

    Remove debug message

commit 029b6e6
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:36:34 2020 +0200

    Clean old notes

commit 1cc7e6e
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:16:02 2020 +0200

    Use the substeps, set the linker output directory

    And re-enable `_RemoveRegisterAttribute` target, as the assemblies now
    end up in the right place

commit e61230f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 12:56:40 2020 +0200

    Build more steps for net5

commit 9ee06d1
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:15:04 2020 +0200

    Run ILLink with our custom SetupStep

    The step so far only installs `FixAbstractMethodsStep`.

    Parts of the code come from xamarin-macios repo. We might share these
    and move them to linker. Or enable more linker API to avoid getting
    the pipeline steps with reflection.

commit 573f854
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:09:21 2020 +0200

    Enable linker on NET5

    Do not run `LinkAssemblies` task on NET5

    Temporarily disable `_RemoveRegisterAttribute` target. It is crashing,
    presumably because the assemblies are in different location.

commit 3df24dc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu Apr 30 16:22:21 2020 +0200

    Add Xamarin.Android.Linker Profile class

    And use it in place of Mono.Tuner one, where needed for net5

commit d6acfe5
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:35:28 2020 +0200

    Use new Context.GetLoadedAssembly on net5

commit 572fa0b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:19:12 2020 +0200

    Use newer linker log API on net5

commit 9cb64f7
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:42 2020 +0200

    Do not check for AppDomain usage on net5

commit 50e4fcc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:01 2020 +0200

    Do not use Mono.Tuner sources in net5 linker

commit 49de381
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:02:47 2020 +0200

    Use the new linker logging iface (conditionaly)

commit 47ad67d
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:01:50 2020 +0200

    Use newer illink nuget

commit b4f6f5c
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Mon Apr 6 21:26:35 2020 -0500

    #if around usage of SafeReadSymbols

commit dbea5d5
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Fri Apr 3 11:10:16 2020 -0500

    [Xamarin.Android.Linker] exploring the new .NET linker

    Based on the new `Microsoft.NET.ILLink` NuGet package, this is a start
    to what it would look like to use it for Xamarin.Android.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jun 3, 2020
Squashed commit of the following:

commit fce7a06
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 26 15:36:50 2020 +0200

    Additional packages for XForms 4.5 on NET5

    To make the test build with linker

commit f7cce5a
Merge: 466ac45 f3bf582
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:37:13 2020 +0200

    Merge branch 'master' into net5-linker

commit 466ac45
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 25 15:22:12 2020 +0200

    Add missing EndProject

    Which fell out in previous merge

commit 324e269
Merge: 759622c 3c868e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:59:09 2020 +0200

    Merge branch 'master' into net5-linker

commit 759622c
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 21 19:52:17 2020 +0200

    Do not require 0 warning for Release

    This can be enabled again when dotnet#4708
    is resolved.

commit 42ba7a2
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 20 16:29:51 2020 +0200

    Add Xamarin.Android.Linker.csproj to solution

    So that it is built

commit 03550e4
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue May 19 19:09:08 2020 +0200

    Set output path to the location used for nuget

commit cb80cad
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:51:48 2020 +0200

    One more `using Mono.Tuner;` missing.

commit ddfcc1f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:22:25 2020 +0200

    One more white space restore

commit 06cc5ee
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:20:41 2020 +0200

    Restore the white space

commit 915d90b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 18 16:14:39 2020 +0200

    Removed a bit too much

    We still need `using Mono.Tuner;` for non NET5 version.

commit 3bafcc9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Fri May 15 17:54:39 2020 +0200

    Get rid of some of the #if's

    We don't need them anymore as we have the new extension method in that
    namespace

commit 3a0f853
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:13:36 2020 +0200

    Set `MonoAndroidHelper.TargetFrameworkDirectories`

commit 9b5497f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu May 14 13:10:45 2020 +0200

    Put the extension in Mono.Linker namespace

    To avoid using Xamarin.Android.Linker namespace and introducing another
    `#if`'s

commit 6aae5e0
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:48:44 2020 +0200

    Add LinkContext.LogMessage extension method

    To avoid few #if's and make the code better readable

commit 340d7e9
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 13 14:28:59 2020 +0200

    Add proguard/r8 support

commit 45c6574
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:15:46 2020 +0200

    Remove old comment

commit c396bec
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 17:13:48 2020 +0200

    Remove debug message

commit 029b6e6
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:36:34 2020 +0200

    Clean old notes

commit 1cc7e6e
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 16:16:02 2020 +0200

    Use the substeps, set the linker output directory

    And re-enable `_RemoveRegisterAttribute` target, as the assemblies now
    end up in the right place

commit e61230f
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Mon May 11 12:56:40 2020 +0200

    Build more steps for net5

commit 9ee06d1
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:15:04 2020 +0200

    Run ILLink with our custom SetupStep

    The step so far only installs `FixAbstractMethodsStep`.

    Parts of the code come from xamarin-macios repo. We might share these
    and move them to linker. Or enable more linker API to avoid getting
    the pipeline steps with reflection.

commit 573f854
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Wed May 6 17:09:21 2020 +0200

    Enable linker on NET5

    Do not run `LinkAssemblies` task on NET5

    Temporarily disable `_RemoveRegisterAttribute` target. It is crashing,
    presumably because the assemblies are in different location.

commit 3df24dc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Thu Apr 30 16:22:21 2020 +0200

    Add Xamarin.Android.Linker Profile class

    And use it in place of Mono.Tuner one, where needed for net5

commit d6acfe5
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:35:28 2020 +0200

    Use new Context.GetLoadedAssembly on net5

commit 572fa0b
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:19:12 2020 +0200

    Use newer linker log API on net5

commit 9cb64f7
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:42 2020 +0200

    Do not check for AppDomain usage on net5

commit 50e4fcc
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:18:01 2020 +0200

    Do not use Mono.Tuner sources in net5 linker

commit 49de381
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:02:47 2020 +0200

    Use the new linker logging iface (conditionaly)

commit 47ad67d
Author: Radek Doulik <radekdoulik@gmail.com>
Date:   Tue Apr 28 16:01:50 2020 +0200

    Use newer illink nuget

commit b4f6f5c
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Mon Apr 6 21:26:35 2020 -0500

    #if around usage of SafeReadSymbols

commit dbea5d5
Author: Jonathan Peppers <jonathan.peppers@microsoft.com>
Date:   Fri Apr 3 11:10:16 2020 -0500

    [Xamarin.Android.Linker] exploring the new .NET linker

    Based on the new `Microsoft.NET.ILLink` NuGet package, this is a start
    to what it would look like to use it for Xamarin.Android.
radekdoulik added a commit that referenced this issue Jun 4, 2020
Implements #4707

With .NET5 we are switching from XA linker implemented as msbuild task to ILLink tool with [custom steps](https://github.com/mono/linker/blob/master/docs/custom-steps.md) provided in an assembly.

The new assembly with our custom steps is named `Microsoft.Android.Sdk.ILLink` and the source code is located in `src/Microsoft.Android.Sdk.ILLink`. It is used during build by `ILLink` tool.

The initial support is already able to link and run simple XA and XA/XF samples.

Future work
* replace reflection usage in SetupStep #4709
* audit reflection usage in our code #4708
* add more customs steps - we are still missing MonoDroidMarkStep

Notes
* the Profile API is not available in the linker [public API](https://github.com/mono/linker/tree/master/src/linker/ref). we work around it by adding `src/Microsoft.Android.Sdk.ILLink/Profile.cs` with missing pieces.
* `TypeDefinition.GetMethods` extension method from `Mono.Tuner.MethodBodyRocks` is not public. It is very simple so we are inlining it.
* the ILLink is now enabled in `Release` configuration defaults.
* tests were updated to reference more packages, to not miss second level dependencies.

Initial results:

apkdiff output summary for HelloAndroid sample, comparing `Debug` and `Release` apk's
```
  -       7,300 Davik executables -2.34% (of 311,436)
  -  14,733,944 Assemblies -31.85% (of 46,265,064)
  -   2,492,452 Shared libraries -11.43% (of 21,803,164)
  -  15,528,456 Package size difference -28.70% (of 54,114,462)
```

Context:
* `_RunILLink` target https://github.com/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.ILLink.targets
* linker documentation https://github.com/mono/linker/tree/master/docs

Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
Co-authored-by: Jonathan Pryor <jonpryor@vt.edu>
@radekdoulik
Copy link
Member Author

Related: #5652

@jonathanpeppers
Copy link
Member

I think we can close this in favor of #5652

@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants