dotnet / linker

389 stars 126 forks source link

Unhandled exception - System.InvalidOperationException #2971

Closed MichaelSimons closed 2 years ago

MichaelSimons commented 2 years ago

Building the runtime repo with a linker from https://github.com/dotnet/linker/commit/81ffbb5af38a45ff60648999df8f35a79061ae43 fails with the following:

  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs(68,13): Trim analysis warning IL2121: System.Linq.Expressions.Compiler.AssemblyGen.DefineDelegateType(String): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2026'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-iOS]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/BinaryExpression.cs(442,13): Trim analysis warning IL2121: System.Linq.Expressions.BinaryExpression.CallGetValueOrDefault(ParameterExpression): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2026'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-iOS]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/BinaryExpression.cs(450,13): Trim analysis warning IL2121: System.Linq.Expressions.BinaryExpression.GetHasValueProperty(ParameterExpression): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2026'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-iOS]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSite.cs(344,13): Trim analysis warning IL2121: System.Runtime.CompilerServices.CallSite<T>.CreateCustomUpdateDelegate(MethodInfo): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2060'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-iOS]
    Fatal error in IL Linker
    Unhandled exception. System.InvalidOperationException: Sequence contains no elements
       at System.Linq.ThrowHelper.ThrowNoElementsException()
       at System.Linq.Enumerable.Last[TSource](IEnumerable`1 source)
       at Mono.Linker.MessageOrigin.ToString()
       at Mono.Linker.MessageContainer.ToMSBuildString()
       at Mono.Linker.MessageContainer.ToString()
       at Mono.Linker.ConsoleLogger.LogMessage(MessageContainer message)
       at Mono.Linker.LinkContext.LogMessage(MessageContainer message)
       at Mono.Linker.LinkContext.FlushCachedWarnings()
       at Mono.Linker.Driver.Run(ILogger customLogger)
       at Mono.Linker.Driver.Main(String[] args)
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/eng/illink.targets(300,5): error MSB6006: "dotnet" exited with code 134. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-iOS]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs(68,13): Trim analysis warning IL2121: System.Linq.Expressions.Compiler.AssemblyGen.DefineDelegateType(String): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2026'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-tvOS]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/BinaryExpression.cs(442,13): Trim analysis warning IL2121: System.Linq.Expressions.BinaryExpression.CallGetValueOrDefault(ParameterExpression): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2026'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-tvOS]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/BinaryExpression.cs(450,13): Trim analysis warning IL2121: System.Linq.Expressions.BinaryExpression.GetHasValueProperty(ParameterExpression): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2026'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-tvOS]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSite.cs(344,13): Trim analysis warning IL2121: System.Runtime.CompilerServices.CallSite<T>.CreateCustomUpdateDelegate(MethodInfo): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2060'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-tvOS]
    Fatal error in IL Linker
    Unhandled exception. System.InvalidOperationException: Sequence contains no elements
       at System.Linq.ThrowHelper.ThrowNoElementsException()
       at System.Linq.Enumerable.Last[TSource](IEnumerable`1 source)
       at Mono.Linker.MessageOrigin.ToString()
       at Mono.Linker.MessageContainer.ToMSBuildString()
       at Mono.Linker.MessageContainer.ToString()
       at Mono.Linker.ConsoleLogger.LogMessage(MessageContainer message)
       at Mono.Linker.LinkContext.LogMessage(MessageContainer message)
       at Mono.Linker.LinkContext.FlushCachedWarnings()
       at Mono.Linker.Driver.Run(ILogger customLogger)
       at Mono.Linker.Driver.Main(String[] args)
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/eng/illink.targets(300,5): error MSB6006: "dotnet" exited with code 134. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-tvOS]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/AssemblyGen.cs(68,13): Trim analysis warning IL2121: System.Linq.Expressions.Compiler.AssemblyGen.DefineDelegateType(String): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2026'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-MacCatalyst]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/BinaryExpression.cs(442,13): Trim analysis warning IL2121: System.Linq.Expressions.BinaryExpression.CallGetValueOrDefault(ParameterExpression): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2026'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-MacCatalyst]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/BinaryExpression.cs(450,13): Trim analysis warning IL2121: System.Linq.Expressions.BinaryExpression.GetHasValueProperty(ParameterExpression): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2026'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-MacCatalyst]
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSite.cs(344,13): Trim analysis warning IL2121: System.Runtime.CompilerServices.CallSite<T>.CreateCustomUpdateDelegate(MethodInfo): Unused 'UnconditionalSuppressMessageAttribute' for warning 'IL2060'. Consider removing the unused warning suppression. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-MacCatalyst]
    Fatal error in IL Linker
    Unhandled exception. System.InvalidOperationException: Sequence contains no elements
       at System.Linq.ThrowHelper.ThrowNoElementsException()
       at System.Linq.Enumerable.Last[TSource](IEnumerable`1 source)
       at Mono.Linker.MessageOrigin.ToString()
       at Mono.Linker.MessageContainer.ToMSBuildString()
       at Mono.Linker.MessageContainer.ToString()
       at Mono.Linker.ConsoleLogger.LogMessage(MessageContainer message)
       at Mono.Linker.LinkContext.LogMessage(MessageContainer message)
       at Mono.Linker.LinkContext.FlushCachedWarnings()
       at Mono.Linker.Driver.Run(ILogger customLogger)
       at Mono.Linker.Driver.Main(String[] args)
  /repos/tarball-linker/src/runtime/artifacts/source-build/self/src/eng/illink.targets(300,5): error MSB6006: "dotnet" exited with code 134. [/repos/tarball-linker/src/runtime/artifacts/source-build/self/src/src/libraries/System.Linq.Expressions/src/System.Linq.Expressions.csproj::TargetFramework=net7.0-MacCatalyst]

This was a recent regression caught by source-build. Here is the failing build (internal Microsoft link)

The previous linker version that was being used and passed was https://github.com/dotnet/linker/commit/f09bacf09ef10b61cf9f19825f8782171a816dab.

Inspecting the code, it seems strange that Last is used here but the two places following that reference correspondingSequencePoint check for null. Should Last be changed to LastOrDefault?

This is blocking source-build for RC1.

Related to https://github.com/dotnet/source-build/issues/2984

MichaelSimons commented 2 years ago

cc @vitek-karas

vitek-karas commented 2 years ago

Looking into this