dotnet / linker

389 stars 127 forks source link

IL Trimmer error when publishing linux self-contained exe with "trim unused code" #3162

Closed NeilMacMullen closed 4 months ago

NeilMacMullen commented 1 year ago

image

See attached build log for full details build_log.txt

Relevant portion appears to be this....


37>IL Trimmer has encountered an unexpected error. Please report the issue at https://github.com/dotnet/linker/issues
37>Fatal error in IL Linker
37>Unhandled exception. System.NotImplementedException: Unhandled intrinsic
37>   at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.HandleCall(Instruction operation, MethodReference calledMethod, ValueSet`1 instanceValue, ImmutableArray`1 argumentValues, DiagnosticContext diagnosticContext, ReflectionMarker reflectionMarker, LinkContext context, MarkStep markStep, ValueSet`1& methodReturnValue)
37>   at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.HandleCall(MethodBody callingMethodBody, MethodReference calledMethod, Instruction operation, ValueNodeList methodParams, ValueSet`1& methodReturnValue)
37>   at Mono.Linker.Dataflow.MethodBodyScanner.HandleCall(MethodBody callingMethodBody, Instruction operation, Stack`1 currentStack, Dictionary`2 locals, InterproceduralState& interproceduralState, Int32 curBasicBlock)
37>   at Mono.Linker.Dataflow.MethodBodyScanner.Scan(MethodBody methodBody, InterproceduralState& interproceduralState)
37>   at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.Scan(MethodBody methodBody, InterproceduralState& interproceduralState)
37>   at Mono.Linker.Dataflow.MethodBodyScanner.InterproceduralScan(MethodBody startingMethodBody)
37>   at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.InterproceduralScan(MethodBody methodBody)
37>   at Mono.Linker.Steps.MarkStep.MarkReflectionLikeDependencies(MethodBody body, Boolean requiresReflectionMethodBodyScanner)
37>   at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
37>   at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method, DependencyInfo& reason, MessageOrigin& origin)
37>   at Mono.Linker.Steps.MarkStep.ProcessQueue()
37>   at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
37>   at Mono.Linker.Steps.MarkStep.Process()
37>   at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
37>   at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
37>   at Mono.Linker.Pipeline.Process(LinkContext context)
37>   at Mono.Linker.Driver.Run(ILogger customLogger)
37>   at Mono.Linker.Driver.Main(String[] args)
37>Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false.

Dotnet info...


➜ dotnet --info
.NET SDK:
 Version:   7.0.100
 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100\

Host:
  Version:      7.0.0
  Architecture: x64
  Commit:       d099f075e4

.NET SDKs installed:
  5.0.404 [C:\Program Files\dotnet\sdk]
  6.0.201 [C:\Program Files\dotnet\sdk]
  7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
 ~                                                                                                                                                                          11:07:24
➜
NeilMacMullen commented 1 year ago

Disabling "Trim unused code" enables the publish operation to succeed (probably not very surprising given the error is with the trimmer!)

marek-safar commented 1 year ago

@vitek-karas can we guess which intrinsic is missing or do we need a repro?

vitek-karas commented 1 year ago

This looks identical to https://github.com/dotnet/linker/issues/3072 Which has a pending 7.0 fix in https://github.com/dotnet/linker/pull/3109

Does the app use a library which is build for netstandard1.6 (or basically anything older than netstandard2.0? If it's the same problem, then a workaround is to rebuild such library to netstandard2.0 - and it should work.

NeilMacMullen commented 1 year ago

Does the app use a library which is build for netstandard1.6 (or basically anything older than netstandard2.0?

No. All libraries are targetting "netstandard2.0" or "net6.0"

vitek-karas commented 1 year ago

Hmm - that would point this to NOT be the same issue as I mention above (or it's unlikely).

Can you try the process described here: https://github.com/dotnet/linker/issues/3160 That will let you run the latest trimmer - to see if we have this fixed in main.

Would it be possible to get a repro project?

NeilMacMullen commented 1 year ago

Would it be possible to get a repro project? Unfortunately it's a fairly complicated proprietary project so unlikely I can cut it down to a repro case. I'll try out the suggested process and let you know results but may take a few days...

jhimes144 commented 1 year ago

For the record, I had the same issue in my very large avalonia android app. It uses many nuget packages so I haven't yet combed through all of them and their dependencies to see which version of .net standard they use.

Doing the process in #3106 seemed to fix my issue.