winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Run ILLinker on Winforms codebase and diff to identify deadcode

Open ericstj opened this issue 6 years ago • 4 comments

ericstj avatar Dec 06 '18 19:12 ericstj

https://github.com/dotnet/core/blob/master/samples/linker-instructions.md

Tanya-Solyanik avatar Dec 06 '18 20:12 Tanya-Solyanik

More info is in this issue in CoreFx https://github.com/dotnet/corefx/issues/17905

ericstj avatar Dec 06 '18 20:12 ericstj

@hughbe this sounds sort of like the work you have been doing?

zsd4yr avatar Jan 10 '19 21:01 zsd4yr

I got a guidance from @eerhardt, putting it here for the future reference.

. . .

The way the linker is run in the dotnet/runtime repo is different than how an application developer runs the linker.

See how the linker is run to generate the report referred above to here: https://github.com/dotnet/runtime/blob/8a2820e35c5ad841d4c3aae3af8b1ace37d22660/eng/illink.targets#L292-L336

It can either be run manually on your assembly, or be automated with MSBuild, like done in dotnet/runtime.

To run it, get the linker from the following NuGet package: https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet5&package=Microsoft.NET.ILLink.Tasks&protocolType=NuGet&version=5.0.0-preview.3.20412.1

And can run it like:

dotnet C:\Users\eerhardt\.nuget\packages\microsoft.net.illink.tasks\5.0.0-preview.3.20410.1\tools\netcoreapp3.0\illink.dll

passing in arguments like:

-reference "<full path to your assembly>"
-out "<full output path>"
-r <assembly name>
-c skip -u skip 
-p link <assembly name>
-t -b true --strip-substitutions false --strip-link-attributes false
--ignore-link-attributes true
--disable-opt unusedinterfaces 
--keep-dep-attributes true 
-d "<full path to a directory that contains references, such as System.Private.CoreLib>"

So a full example:

-reference "F:\git\runtime\artifacts\obj\Microsoft.Extensions.Caching.Abstractions\netstandard2.0-Debug\Microsoft.Extensions.Caching.Abstractions.dll"
-out "C:\temp\junk"
-r Microsoft.Extensions.Caching.Abstractions
-c skip -u skip 
-p link Microsoft.Extensions.Caching.Abstractions
-t -b true --strip-substitutions false --strip-link-attributes false
--ignore-link-attributes true
--disable-opt unusedinterfaces 
--keep-dep-attributes true 
-d "F:\git\runtime\artifacts\bin\microsoft.netcore.app.runtime.win-x64\Debug\runtimes\win-x64\lib\net5.0"

The above arguments can be put in a .rsp file, and then pass that file on the command line with an @ sign before the file name: dotnet <path-to-linker> @commandArgs.rsp.

After the assembly is linked, it can be diff'ed it using asmdiff.exe using the same args in that illink.targets file above.

RussKie avatar Aug 17 '20 04:08 RussKie