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

Unable to generate linker-dependencies.xml for Windows SDK projects #3212

Open
mitchcapper opened this issue Apr 9, 2023 · 3 comments
Open

Comments

@mitchcapper
Copy link

per: https://github.com/dotnet/linker/blob/main/src/analyzer/README.md
it seems like this should work for .net SDK style projects but I am having no luck.

I created a simple repro test case and built it using
msbuild /p:_TrimmerDumpDependencies=true /p:Configuration=Release /t:Rebuild

but no linker xml file is generated. Attached is the project and the build output.
LinkerAnalyzerFail.zip
msbuild_output.txt

@vitek-karas
Copy link
Member

Your project uses PublishAot=true which will end up using the AOT compiler (ilc), not the illink tool. The _TrimmerDumpDependencies property only acts when the illink tool is used.

You do have IlcGenerateDgmlFile which is the equivalent functionality for the AOT compiler. This should produce a .dgml file in obj\<Configuration>\<TFM>\<RID>\native\. You can used the DependencyGraphViewer tool to inspect it: https://github.com/dotnet/runtime/tree/main/src/coreclr/tools/aot/DependencyGraphViewer

Alternatively you can publish your project without AOT so /p:PublishAot=false /p:PublishTrimmed=true in which case the illink will be used and you will be able to use the analyzer tool from this repo.

Note that the trimming behavior between illink and ilc can be different, the tools have somewhat different capabilities in some areas.

Also note that the development of illink and all of the related tools has moved to the dotnet/runtime repo.

@mitchcapper
Copy link
Author

mitchcapper commented Apr 11, 2023

Hrm. Still no luck. Removed the Properties folder from that sample and updated the project:

cat .\LinkerAnalyzerFail.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0-windows10.0.22621.0</TargetFramework>
    <SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
          <TrimMode>full</TrimMode>
          <EnableTrimAnalyzer>true</EnableTrimAnalyzer>
          <TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>
          <PublishAot>false</PublishAot>
          <StripSymbols>true</StripSymbols>
          <SelfContained>true</SelfContained>
          <PublishTrimmed>true</PublishTrimmed>
          <PublishSingleFile>true</PublishSingleFile>
          <DebuggerSupport>false</DebuggerSupport>
          <PublishReadyToRun>false</PublishReadyToRun>
          <EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>
          <EnableUnsafeUTF7Encoding>false</EnableUnsafeUTF7Encoding>
          <EventSourceSupport>false</EventSourceSupport>
          <HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
          <InvariantGlobalization>true</InvariantGlobalization>
          <MetadataUpdaterSupport>false</MetadataUpdaterSupport>
          <UseNativeHttpHandler>true</UseNativeHttpHandler>
          <UseSystemResourceKeys>true</UseSystemResourceKeys>
          <IlcGenerateDgmlFile>true</IlcGenerateDgmlFile>
  </PropertyGroup>

</Project>

dotnet restore
Determining projects to restore...
Restored LinkerAnalyzerFail.csproj (in 104 ms).
msbuild /p:_TrimmerDumpDependencies=true /p:Configuration=Release /p:PublishAot=false /p:PublishTrimmed=true /t:Rebuild

  LinkerAnalyzerFail -> bin\Release\net7.0-windows10.0.22621.0\win-x64\LinkerAnalyzerFail.dll
  Copying file from "obj\Release\net7.0-windows10.0.22621.0\win-x64\LinkerAnalyzerFail.pdb" to "bin\Release\net7.0-windows10.0.22621.0\win-x64\LinkerAnalyzerFail.pdb".
Done Building Project "LinkerAnalyzerFail.csproj" (Rebuild target(s)).

Done Building Project "LinkerAnalyzerFail.sln" (Rebuild target(s)).

find | grep -i xml

./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Private.Xml.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Private.Xml.Linq.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Runtime.Serialization.Xml.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Xml.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Xml.Linq.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Xml.ReaderWriter.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Xml.Serialization.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Xml.XDocument.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Xml.XmlDocument.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Xml.XmlSerializer.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Xml.XPath.dll
./bin/Release/net7.0-windows10.0.22621.0/win-x64/System.Xml.XPath.XDocument.dll

I am not sure where I found the link to this or the docs talking about native AOT size optimization so its possible I read it wrong or it wasn't clear one vs the other. In terms of the wrong repo I do see it at https://github.com/dotnet/runtime/tree/main/src/tools/illink/src/analyzer for this (potential) bug not sure if I should re-file it under dotnet runtime.

@vitek-karas
Copy link
Member

The instructions are only valid for Xamarin projects. For console projects the trimmer/aot only runs during publish.
I opened a PR to fix the doc in the runtime repo (for the analyzer tool): dotnet/runtime#84833

To get the linker dependencies XML usable by the analyzer tool:
dotnet publish /p:PublishTrimmed=true /p:_TrimmerDumpDependencies=true
The output is in obj/Release/net7.0-windows10.0.22621.0/win-x64/linked/linker-dependencies.xml. This file can be consumed by the illinkanalyzer tool.

You can also get dgml file from the illink:
dotnet publish /p:PublishTrimmed=true /p:_TrimmerDumpDependencies=true /p:_TrimmerDependenciesFileFormat=dgml
The output is now in obj\Release\net7.0-windows10.0.22621.0\win-x64\linked\linker-dependencies.dgml.
This can be consumed by the DependencyGraphViewer tool in https://github.com/dotnet/runtime/tree/main/src/coreclr/tools/aot/DependencyGraphViewer.

NativeAOT can only produce the dgml file:
dotnet publish /p:PublishAot=true /p:IlcGenerateDgmlFile=true
The output is going to be in obj\Release\net7.0-windows10.0.22621.0\win-x64\native\<app>.codegen.dgml.xml (and another file called <app>.scan.dgml.xml since the compiler does too passes on the input, so two dependency graphs).
This can be consumed by the DependencyGraphViewer tool as well.

There's some additional details about some of this here: https://github.com/dotnet/runtime/tree/main/src/coreclr/tools/aot/DependencyGraphViewer#readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants