dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.71k stars 1.06k forks source link

Crossgen2 attempting to generate PDB on Linux #23072

Open MichalStrehovsky opened 2 years ago

MichalStrehovsky commented 2 years ago

Reported on Discord. See the log here. The relevant part of the log:

2021-12-14T22:08:55.7020464Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error : Error: Cannot marshal 'parameter #3': Invalid managed/unmanaged type combination (Marshaling to and from COM interface pointers isn't supported). [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]
2021-12-14T22:08:55.7038775Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error : System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'parameter #3': Invalid managed/unmanaged type combination (Marshaling to and from COM interface pointers isn't supported). [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]
2021-12-14T22:08:55.7043929Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Diagnostics.PdbWriter.CreateNGenPdbWriter(String ngenImagePath, String pdbPath, ISymNGenWriter2& ngenPdbWriter) [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]
2021-12-14T22:08:55.7048913Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Diagnostics.PdbWriter.WritePDBDataHelper(String dllPath, IEnumerable`1 methods) [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]
2021-12-14T22:08:55.7053254Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Diagnostics.PdbWriter.WritePDBData(String dllPath, IEnumerable`1 methods) [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]
2021-12-14T22:08:55.7057400Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.PEWriter.SymbolFileBuilder.SavePdb(String pdbPath, String dllFileName) [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]
2021-12-14T22:08:55.7062283Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.DependencyAnalysis.ReadyToRunObjectWriter.EmitPortableExecutable() [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]
2021-12-14T22:08:55.7067173Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile) [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]
2021-12-14T22:08:55.7072490Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, CompilerTypeSystemContext typeSystemContext) [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]
2021-12-14T22:08:55.7087950Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Program.Run(String[] args) [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]
2021-12-14T22:08:55.7091569Z /home/runner/.dotnet/sdk/6.0.200-preview.21614.10/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(463,5): error :    at ILCompiler.Program.Main(String[] args) [/home/runner/work/runtime/runtime/pkg/Elskom.Sdk.App.Runtime/Elskom.Sdk.App.win-arm64.sfxproj]

It looks like crossgen2 is attempting to generate a PDB when running on Linux, but targeting Windows.

I don't see a check that would prevent this. The closest one is:

https://github.com/dotnet/sdk/blob/cf2fd1e514c393cb12e745ab488b6478320fc232/src/Tasks/Microsoft.NET.Build.Tasks/RunReadyToRunCompiler.cs#L321-L325

But that one only checks the target and not the host. The problem is that PDB can only be created when the host is Windows because it uses COM APIs that are only available on Windows.

Cc @dotnet/crossgen-contrib @AntonLapounov

AntonLapounov commented 2 years ago

Thank you for reporting this. I think we need to add checks to both SDK (ValidateCrossgen2Support would be a good place) https://github.com/dotnet/sdk/blob/f2a00822cb7f182ecf91e0abb0dfa3679748bf2d/src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs#L134 and Crossgen2 compiler.

elachlan commented 2 years ago

It seems like this code block in ValidateCrossgen2Support would return false (not available): https://github.com/dotnet/sdk/blob/046aea514d5c489ee402886755bd7d71e256f77a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveReadyToRunCompilers.cs#L155-L168

https://docs.microsoft.com/en-us/dotnet/core/deploying/ready-to-run#cross-platformarchitecture-restrictions Cross compile from Linux to Windows I don't think is supported.

trylek commented 2 years ago

I think that the primary check should be in Crossgen2, it should bail out before trying to call non-existent DIA APIs on Unix. A secondary check in SDK would be also useful to support a smoother developer experience.