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

Referencing OpenTK.Graphics crashes the Ready2Run build. #59138

Closed
ChrisKoebke opened this issue Sep 15, 2021 · 14 comments
Closed

Referencing OpenTK.Graphics crashes the Ready2Run build. #59138

ChrisKoebke opened this issue Sep 15, 2021 · 14 comments
Assignees
Milestone

Comments

@ChrisKoebke
Copy link

Description

When referencing OpenTK.Graphics, I'm getting a an ILCompiler.CodeGenerationFailedException on a Ready2Run publish and the build fails.

Configuration

  • .NET 6 (RC1)
  • VS2022 Version 17.0.0 Preview 4.0
  • Windows 10
  • x64
  • C# 10.0

The configuration for Publish is the same as in this issue

Other information

Stack Trace:
===========
2>Error: One or more errors occurred. (Code generation failed for method '[OpenTK.Graphics]OpenTK.Graphics.ES11.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32*)')
2>System.AggregateException: One or more errors occurred. (Code generation failed for method '[OpenTK.Graphics]OpenTK.Graphics.ES11.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32*)')
2> ---> ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK.Graphics]OpenTK.Graphics.ES11.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32*)'
2>   at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
2>   at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodWithGCInfo methodCodeNodeNeedingCode, Logger logger)
2>   at ILCompiler.ReadyToRunCodegenCompilation.<ComputeDependencyNodeDependencies>b__36_0(DependencyNodeCore`1 dependency)
2>   at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
2>   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
2>--- End of stack trace from previous location ---
2>   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
2>   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
2>   --- End of inner exception stack trace ---
2>   at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
2>   at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
2>--- End of stack trace from previous location ---
2>   at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
2>   at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
2>   at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IList`1 list, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
2>   at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
2>   at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
2>   at ILCompiler.ReadyToRunCodegenCompilation.ComputeDependencyNodeDependencies(List`1 obj)
2>   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes()
2>   at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile)
2>   at ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, CompilerTypeSystemContext typeSystemContext)
2>   at ILCompiler.Program.Run(String[] args)
2>   at ILCompiler.Program.Main(String[] args)

Full Log:
=============
Build started...
1>------ Build started: Project: ConsoleApp3, Configuration: Release Any CPU ------
1>Build started 15/09/2021 08:39:03.
1>Target _CheckForNETCoreSdkIsPreview:
1>  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
1>Target GenerateTargetFrameworkMonikerAttribute:
1>  Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>Target CoreGenerateAssemblyInfo:
1>  Skipping target "CoreGenerateAssemblyInfo" because all output files are up-to-date with respect to the input files.
1>Target CoreCompile:
1>  Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
1>Target _CreateAppHost:
1>  Skipping target "_CreateAppHost" because all output files are up-to-date with respect to the input files.
1>Target _CopyOutOfDateSourceItemsToOutputDirectory:
1>  Skipping target "_CopyOutOfDateSourceItemsToOutputDirectory" because all output files are up-to-date with respect to the input files.
1>Target GenerateBuildDependencyFile:
1>  Skipping target "GenerateBuildDependencyFile" because all output files are up-to-date with respect to the input files.
1>Target GenerateBuildRuntimeConfigurationFiles:
1>  Skipping target "GenerateBuildRuntimeConfigurationFiles" because all output files are up-to-date with respect to the input files.
1>Target CopyFilesToOutputDirectory:
1>  ConsoleApp3 -> C:\Users\Win10 Home x64\source\repos\ConsoleApp3\ConsoleApp3\bin\Release\net6.0\ConsoleApp3.dll
1>Target IncrementalClean:
1>  Deleting file "C:\Users\Win10 Home x64\source\repos\ConsoleApp3\ConsoleApp3\obj\Release\net6.0\ConsoleApp3.csproj.CopyComplete".
1>
1>Build succeeded.
1>    0 Warning(s)
1>    0 Error(s)
1>
1>Time Elapsed 00:00:00.41
2>------ Publish started: Project: ConsoleApp3, Configuration: Release Any CPU ------
2>Determining projects to restore...
2>Committing restore...
2>Assets file has not changed. Skipping assets file writing. Path: C:\Users\Win10 Home x64\source\repos\ConsoleApp3\ConsoleApp3\obj\publish\win-x64\project.assets.json
2>Restored C:\Users\Win10 Home x64\source\repos\ConsoleApp3\ConsoleApp3\ConsoleApp3.csproj (in 68 ms).
2>
2>NuGet Config files used:
2>    C:\Users\Win10 Home x64\AppData\Roaming\NuGet\NuGet.Config
2>    C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
2>
2>Feeds used:
2>    https://api.nuget.org/v3/index.json
2>    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
2>All projects are up-to-date for restore.
2>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
2>Skipping target "CoreGenerateAssemblyInfo" because all output files are up-to-date with respect to the input files.
2>Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateAppHost" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CopyOutOfDateSourceItemsToOutputDirectory" because all output files are up-to-date with respect to the input files.
2>Skipping target "GenerateBuildDependencyFile" because all output files are up-to-date with respect to the input files.
2>Skipping target "GenerateBuildRuntimeConfigurationFiles" because all output files are up-to-date with respect to the input files.
2>ConsoleApp3 -> C:\Users\Win10 Home x64\source\repos\ConsoleApp3\ConsoleApp3\bin\Release\net6.0\win-x64\ConsoleApp3.dll
2>Deleting file "C:\Users\Win10 Home x64\source\repos\ConsoleApp3\ConsoleApp3\obj\Release\net6.0\win-x64\ConsoleApp3.csproj.CopyComplete".
2>Skipping target "_RunILLink" because all output files are up-to-date with respect to the input files.
2>Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>C:\Users\Win10 Home x64\.nuget\packages\microsoft.netcore.app.crossgen2.win-x64\6.0.0-rc.1.21451.13\tools\crossgen2.exe --targetos:windows
2>--targetarch:x64
2>-O
2>-r:"obj\Release\net6.0\win-x64\linked\OpenTK.Core.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\OpenTK.Graphics.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\OpenTK.Mathematics.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\ConsoleApp3.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Collections.Immutable.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Collections.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.ComponentModel.Primitives.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.ComponentModel.TypeConverter.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Console.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Diagnostics.StackTrace.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Drawing.Primitives.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Drawing.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.IO.Compression.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.IO.MemoryMappedFiles.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.ObjectModel.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Private.CoreLib.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Private.Xml.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Reflection.Metadata.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Runtime.CompilerServices.Unsafe.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Runtime.Extensions.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Runtime.InteropServices.RuntimeInformation.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Runtime.InteropServices.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Runtime.Intrinsics.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Runtime.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\System.Xml.ReaderWriter.dll"
2>-r:"obj\Release\net6.0\win-x64\linked\netstandard.dll"
2>--out:"obj\Release\net6.0\win-x64\R2R\OpenTK.Graphics.dll"
2>obj\Release\net6.0\win-x64\linked\OpenTK.Graphics.dll
2>
2>Error: One or more errors occurred. (Code generation failed for method '[OpenTK.Graphics]OpenTK.Graphics.ES11.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32*)')
2>System.AggregateException: One or more errors occurred. (Code generation failed for method '[OpenTK.Graphics]OpenTK.Graphics.ES11.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32*)')
2> ---> ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK.Graphics]OpenTK.Graphics.ES11.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32*)'
2>   at Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL)
2>   at Internal.JitInterface.CorInfoImpl.CompileMethod(MethodWithGCInfo methodCodeNodeNeedingCode, Logger logger)
2>   at ILCompiler.ReadyToRunCodegenCompilation.<ComputeDependencyNodeDependencies>b__36_0(DependencyNodeCore`1 dependency)
2>   at System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i)
2>   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
2>--- End of stack trace from previous location ---
2>   at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
2>   at System.Threading.Tasks.TaskReplicator.Replica.Execute()
2>   --- End of inner exception stack trace ---
2>   at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean stopOnFirstFailure)
2>   at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
2>--- End of stack trace from previous location ---
2>   at System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
2>   at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
2>   at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IList`1 list, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
2>   at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
2>   at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
2>   at ILCompiler.ReadyToRunCodegenCompilation.ComputeDependencyNodeDependencies(List`1 obj)
2>   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes()
2>   at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile)
2>   at ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, CompilerTypeSystemContext typeSystemContext)
2>   at ILCompiler.Program.Run(String[] args)
2>   at ILCompiler.Program.Main(String[] args)
2>Build continuing because "ContinueOnError" on the task "RunReadyToRunCompiler" is set to "ErrorAndContinue".
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Skipping target "_CreateR2RImages" because all output files are up-to-date with respect to the input files.
2>Optimizing assemblies for performance failed. You can either exclude the failing assemblies from being optimized, or set the PublishReadyToRun property to false.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Sep 15, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ChrisKoebke
Copy link
Author

ChrisKoebke commented Sep 15, 2021

To reproduce this:
ConsoleApp3.zip

@mangod9 mangod9 removed the untriaged New issue has not been triaged by the area owner label Sep 15, 2021
@mangod9 mangod9 modified the milestones: 7.0.0, 6.0.0 Sep 15, 2021
@mangod9
Copy link
Member

mangod9 commented Sep 15, 2021

@trylek could you please take a look at this?

@trylek
Copy link
Member

trylek commented Sep 15, 2021

Sure, taking a look now.

@trylek
Copy link
Member

trylek commented Sep 15, 2021

OK, so the proximate failure is caused by this assertion failure:

            case BBJ_CALLFINALLY:
            case BBJ_EHCATCHRET:
            case BBJ_RETURN:
            case BBJ_EHFINALLYRET:
            case BBJ_EHFILTERRET:
            case BBJ_THROW:
                NO_WAY("can't have 'unreached' end of BB with non-empty stack");
                break;

at

NO_WAY("can't have 'unreached' end of BB with non-empty stack");

due to block->bbJumpKind being equal to BBJ_RETURN. This happens while compiling the method [OpenTK.Graphics]OpenTK.Graphics.ES11.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32*) with the following IL source code:

    .method /*0600661E*/ public hidebysig static 
            void  ExtGetProgramBinarySource(uint32 program,
                                            valuetype OpenTK.Graphics.ES11.ShaderType/*02000B69*/ shadertype,
                                            [out] string& source,
                                            [out] int32* length) cil managed
    {
      .custom /*0C006B31:0A00001E*/ instance void [System.Runtime/*23000001*/]System.CLSCompliantAttribute/*01000016*/::.ctor(bool) /* 0A00001E */ = ( 01 00 00 00 00 ) 
      // 
      .maxstack  7
      .locals /*11000005*/ init (native int V_0,
               int32 V_1)
      IL_0000:  ldarg.0
      IL_0001:  ldarg.1
      IL_0002:  ldarg.2
      IL_0003:  pop
      IL_0004:  ldarg.3
      IL_0005:  ldind.i4
      IL_0006:  ldloc.1
      IL_0007:  ldc.i4.1
      IL_0008:  add
      IL_0009:  call       native int [System.Private.CoreLib/*23000008*/]System.Runtime.InteropServices.Marshal/*0100001C*/::AllocHGlobal(native int) /* 0A000023 */
      IL_000e:  stloc.0
      IL_000f:  ldloc.0
      IL_0010:  ldarg.3
      IL_0011:  ldsfld     native int[] OpenTK.Graphics.ES11.GL/*02000A4C*/::EntryPoints /* 0400B09A */
      IL_0016:  ldc.i4.s   102
      IL_0018:  ldelem.i
      IL_0019:  calli      unmanaged stdcall void(uint32,int32,native int,int32*) /*11000113*/
      IL_001e:  ldarg.2
      IL_001f:  ldloc.0
      IL_0020:  call       string OpenTK.Graphics.BindingsBase/*0200001E*/::MarshalPtrToString(native int) /* 06000002 */
      IL_0025:  stind.ref
      IL_0026:  ldloc.0
      IL_0027:  call       void [System.Private.CoreLib/*23000008*/]System.Runtime.InteropServices.Marshal/*0100001C*/::FreeHGlobal(native int) /* 0A000024 */
      IL_002c:  ret
    } // end of method Qcom::ExtGetProgramBinarySource

This is the NgenDump for the method:

****** START compiling Qcom:ExtGetProgramBinarySource(int,int,byref,long) (MethodHash=f0d1279b)
Generating code for Windows x64
OPTIONS: compCodeOpt = BLENDED_CODE
OPTIONS: compDbgCode = false
OPTIONS: compDbgInfo = true
OPTIONS: compDbgEnC  = false
OPTIONS: compProcedureSplitting   = false
OPTIONS: compProcedureSplittingEH = false
OPTIONS: No PGO data
OPTIONS: Jit invoked for ngen
IL to import:
IL_0000  02                ldarg.0
IL_0001  03                ldarg.1
IL_0002  04                ldarg.2
IL_0003  26                pop
IL_0004  05                ldarg.3
IL_0005  4a                ldind.i4
IL_0006  07                ldloc.1
IL_0007  17                ldc.i4.1
IL_0008  58                add
IL_0009  28 23 00 00 0a    call         0xA000023
IL_000e  0a                stloc.0
IL_000f  06                ldloc.0
IL_0010  05                ldarg.3
IL_0011  7e 9a b0 00 04    ldsfld       0x400B09A
IL_0016  1f 66             ldc.i4.s     0x66
IL_0018  97                ldelem.i
IL_0019  29 13 01 00 11    calli        0x11000113
IL_001e  04                ldarg.2
IL_001f  06                ldloc.0
IL_0020  28 02 00 00 06    call         0x6000002
IL_0025  51                stind.ref
IL_0026  06                ldloc.0
IL_0027  28 24 00 00 0a    call         0xA000024
IL_002c  2a                ret
Arg #0    passed in register(s) rcx
Arg #1    passed in register(s) rdx
Arg #2    passed in register(s) r8
Arg #3    passed in register(s) r9

lvaGrabTemp returning 6 (V06 tmp0) (a long lifetime temp) called for OutgoingArgSpace.
; Initial local variable assignments
;
;  V00 arg0              int
;  V01 arg1              int
;  V02 arg2            byref
;  V03 arg3             long
;  V04 loc0             long
;  V05 loc1              int
;  V06 OutArgs        lclBlk   "OutgoingArgSpace"
*************** In compInitDebuggingInfo() for Qcom:ExtGetProgramBinarySource(int,int,byref,long)
getVars() returned cVars = 0, extendOthers = true
info.compVarScopesCount = 6
        VarNum  LVNum         Name      Beg     End
 0:     00h     00h       V00 arg0      000h    02Dh
 1:     01h     01h       V01 arg1      000h    02Dh
 2:     02h     02h       V02 arg2      000h    02Dh
 3:     03h     03h       V03 arg3      000h    02Dh
 4:     04h     04h       V04 loc0      000h    02Dh
 5:     05h     05h       V05 loc1      000h    02Dh
info.compStmtOffsetsCount    = 0
info.compStmtOffsetsImplicit = 0007h ( STACK_EMPTY NOP CALL_SITE )
*************** In fgFindBasicBlocks() for Qcom:ExtGetProgramBinarySource(int,int,byref,long)
weight= 10 : state   3 [ ldarg.0 ]
weight= 16 : state   4 [ ldarg.1 ]
weight= 35 : state   5 [ ldarg.2 ]
weight=-24 : state  39 [ pop ]
weight= 28 : state   6 [ ldarg.3 ]
weight=-11 : state  62 [ ldind.i4 ]
weight=  9 : state   8 [ ldloc.1 ]
weight= 28 : state  24 [ ldc.i4.1 ]
weight=-12 : state  76 [ add ]
weight= 79 : state  40 [ call ]
weight= 20 : state 199 [ stloc.0 -> ldloc.0 ]
weight= 28 : state   6 [ ldarg.3 ]
weight=159 : state 112 [ ldsfld ]
weight= 41 : state  32 [ ldc.i4.s ]
weight= 65 : state 128 [ ldelem.i ]
weight= 65 : state  41 [ calli ]
weight= 35 : state   5 [ ldarg.2 ]
weight= 12 : state   7 [ ldloc.0 ]
weight= 79 : state  40 [ call ]
weight= 60 : state  69 [ stind.ref ]
weight= 12 : state   7 [ ldloc.0 ]
weight= 79 : state  40 [ call ]
weight= 19 : state  42 [ ret ]
Marked V04 as a single def local
Marked V05 as a single def local
Jump targets:
  none
New Basic Block BB01 [0000] created.
BB01 [000..02D)

Inline candidate looks like a wrapper method.  Multiplier increased to 1.
Inline candidate callsite is hot.  Multiplier increased to 4.
Callsite has profile data: 1.  Multiplier limited to 16.8.
calleeNativeSizeEstimate=832
callsiteNativeSizeEstimate=175
benefit multiplier=16.8
threshold=2940
Native estimate for function size is within threshold for inlining 83.2 <= 294 (multiplier = 16.8)
IL Code Size,Instr   45,  24, Basic Block count   1, Local Variable Num,Ref count   7, 11 for method Qcom:ExtGetProgramBinarySource(int,int,byref,long)
OPTIONS: opts.MinOpts() == false
Basic block list for 'Qcom:ExtGetProgramBinarySource(int,int,byref,long)'

-----------------------------------------------------------------------------------------------------------------------------------------
BBnum BBid ref try hnd                 weight    lp [IL range]     [jump]      [EH region]         [flags]
-----------------------------------------------------------------------------------------------------------------------------------------
BB01 [0000]  1                             1       [000..02D)        (return)
-----------------------------------------------------------------------------------------------------------------------------------------

*************** Starting PHASE Pre-import

*************** Finishing PHASE Pre-import

*************** Starting PHASE Profile incorporation
BBOPT set, but no profile data available (hr=80004001)

*************** Finishing PHASE Profile incorporation [no changes]

*************** Starting PHASE Importation
*************** In impImport() for Qcom:ExtGetProgramBinarySource(int,int,byref,long)

impImportBlockPending for BB01

Importing BB01 (PC=000) of 'Qcom:ExtGetProgramBinarySource(int,int,byref,long)'
    [ 0]   0 (0x000) ldarg.0
    [ 1]   1 (0x001) ldarg.1
    [ 2]   2 (0x002) ldarg.2
    [ 3]   3 (0x003) pop
    [ 2]   4 (0x004) ldarg.3
    [ 3]   5 (0x005) ldind.i4
    [ 3]   6 (0x006) ldloc.1
    [ 4]   7 (0x007) ldc.i4.1 1
    [ 5]   8 (0x008) add
    [ 4]   9 (0x009) call 0A000023
In Compiler::impImportCall: opcode is call, kind=0, callRetType is long, structSize is 0

lvaGrabTemp returning 7 (V07 tmp1) called for non-inline candidate call.


STMT00000 (IL 0x000...  ???)
               [000011] -A-XG-------              *  ASG       int
               [000010] D------N----              +--*  LCL_VAR   int    V07 tmp1
               [000004] *--XG-------              \--*  IND       int
               [000003] ------------                 \--*  LCL_VAR   long   V03 arg3

    [ 4]  14 (0x00e) stloc.0

STMT00001 (IL   ???...  ???)
               [000014] -AC-G-------              *  ASG       long
               [000013] D------N----              +--*  LCL_VAR   long   V04 loc0
               [000008] --C-G-------              \--*  CALL r2r_ind long   System.Runtime.InteropServices.Marshal.AllocHGlobal
               [000009] ------------ arg0            \--*  CAST      long <- int
               [000007] ------------                    \--*  ADD       int
               [000005] ------------                       +--*  LCL_VAR   int    V05 loc1
               [000006] ------------                       \--*  CNS_INT   int    1

    [ 3]  15 (0x00f) ldloc.0
    [ 4]  16 (0x010) ldarg.3
    [ 5]  17 (0x011) ldsfld 0400B09A
    [ 6]  22 (0x016) ldc.i4.s 102
    [ 7]  24 (0x018) ldelem.i
    [ 6]  25 (0x019) calli 11000113
lvaGrabTemp returning 8 (V08 tmp2) called for impImportIndirectCall.


STMT00002 (IL   ???...  ???)
               [000024] -ACXG-------              *  ASG       long
               [000023] D------N----              +--*  LCL_VAR   long   V08 tmp2
               [000022] --CXG-------              \--*  INDEX     long
               [000020] --CXG-------                 +--*  IND       ref
               [000019] --CXG-------                 |  \--*  ADD       byref
               [000017] --CXG-------                 |     +--*  CALL help r2r_ind byref  HELPER.CORINFO_HELP_READYTORUN_STATIC_BASE
               [000018] ------------                 |     \--*  CNS_INT   int    88 Fseq[EntryPoints]
               [000021] ------------                 \--*  CNS_INT   int    102

In Compiler::impImportCall: opcode is calli, kind=0, callRetType is void, structSize is 0

Inline a CALLI PINVOKE call from method Qcom:ExtGetProgramBinarySource(int,int,byref,long)INLINER: during 'impMarkInlineCandidate' result 'failed this call site' reason 'target not direct managed' for 'Qcom:ExtGetProgramBinarySource(int,int,byref,long)' calling 'n/a'
INLINER: during 'impMarkInlineCandidate' result 'failed this call site' reason 'target not direct managed'


STMT00003 (IL   ???...  ???)
               [000026] --CXG-------              *  CALL ind unman void
               [000001] ------------ arg0         +--*  LCL_VAR   int    V01 arg1
               [000012] ------------ arg1         +--*  LCL_VAR   int    V07 tmp1
               [000015] ------------ arg2         +--*  LCL_VAR   long   V04 loc0
               [000016] ------------ arg3         +--*  LCL_VAR   long   V03 arg3
               [000025] ------------ calli tgt    \--*  LCL_VAR   long   V08 tmp2

    [ 1]  30 (0x01e) ldarg.2
    [ 2]  31 (0x01f) ldloc.0
    [ 3]  32 (0x020) call 06000002
In Compiler::impImportCall: opcode is call, kind=0, callRetType is ref, structSize is 0


STMT00004 (IL 0x01E...  ???)
               [000029] I-C-G-------              *  CALL r2r_ind ref    OpenTK.Graphics.BindingsBase.MarshalPtrToString (exactContextHnd=0x4000000000420051)
               [000028] ------------ arg0         \--*  LCL_VAR   long   V04 loc0

    [ 3]  37 (0x025) stind.ref

STMT00005 (IL   ???...  ???)
               [000032] -ACXG-------              *  ASG       ref
               [000031] *------N----              +--*  IND       ref
               [000027] ------------              |  \--*  LCL_VAR   byref  V02 arg2
               [000030] --C---------              \--*  RET_EXPR  ref   (inl return expr [000029])

    [ 1]  38 (0x026) ldloc.0
    [ 2]  39 (0x027) call 0A000024
 (Implicit Tail call: prefixFlags |= PREFIX_TAILCALL_IMPLICIT)
In Compiler::impImportCall: opcode is call, kind=0, callRetType is void, structSize is 0
Detected unsafe code: importer.cpp:9286 : Stack should be empty after tailcall, while compiling Qcom:ExtGetProgramBinarySource(int,int,byref,long) opcode call, IL offset 27

info.compCompHnd->canTailCall returned false for call [000034]


STMT00006 (IL   ???...  ???)
               [000034] --C-G-------              *  CALL r2r_ind void   System.Runtime.InteropServices.Marshal.FreeHGlobal
               [000033] ------------ arg0         \--*  LCL_VAR   long   V04 loc0

    [ 1]  44 (0x02c) ret

STMT00007 (IL 0x02C...  ???)
               [000035] ------------              *  RETURN    void
****** START compiling Qcom:ExtGetProgramBinarySource(int,int,byref,long) (MethodHash=f0d1279b)
Generating code for Windows x64
OPTIONS: compCodeOpt = BLENDED_CODE
OPTIONS: compDbgCode = false
OPTIONS: compDbgInfo = true
OPTIONS: compDbgEnC  = false
OPTIONS: compProcedureSplitting   = false
OPTIONS: compProcedureSplittingEH = false
OPTIONS: No PGO data
OPTIONS: Jit invoked for ngen
IL to import:
IL_0000  02                ldarg.0
IL_0001  03                ldarg.1
IL_0002  04                ldarg.2
IL_0003  26                pop
IL_0004  05                ldarg.3
IL_0005  4a                ldind.i4
IL_0006  07                ldloc.1
IL_0007  17                ldc.i4.1
IL_0008  58                add
IL_0009  28 23 00 00 0a    call         0xA000023
IL_000e  0a                stloc.0
IL_000f  06                ldloc.0
IL_0010  05                ldarg.3
IL_0011  7e 9a b0 00 04    ldsfld       0x400B09A
IL_0016  1f 66             ldc.i4.s     0x66
IL_0018  97                ldelem.i
IL_0019  29 13 01 00 11    calli        0x11000113
IL_001e  04                ldarg.2
IL_001f  06                ldloc.0
IL_0020  28 02 00 00 06    call         0x6000002
IL_0025  51                stind.ref
IL_0026  06                ldloc.0
IL_0027  28 24 00 00 0a    call         0xA000024
IL_002c  2a                ret
Arg #0    passed in register(s) rcx
Arg #1    passed in register(s) rdx
Arg #2    passed in register(s) r8
Arg #3    passed in register(s) r9

lvaGrabTemp returning 6 (V06 tmp0) (a long lifetime temp) called for OutgoingArgSpace.
; Initial local variable assignments
;
;  V00 arg0              int
;  V01 arg1              int
;  V02 arg2            byref
;  V03 arg3             long
;  V04 loc0             long
;  V05 loc1              int
;  V06 OutArgs        lclBlk   "OutgoingArgSpace"
*************** In compInitDebuggingInfo() for Qcom:ExtGetProgramBinarySource(int,int,byref,long)
getVars() returned cVars = 0, extendOthers = true
info.compVarScopesCount = 6
        VarNum  LVNum         Name      Beg     End
 0:     00h     00h       V00 arg0      000h    02Dh
 1:     01h     01h       V01 arg1      000h    02Dh
 2:     02h     02h       V02 arg2      000h    02Dh
 3:     03h     03h       V03 arg3      000h    02Dh
 4:     04h     04h       V04 loc0      000h    02Dh
 5:     05h     05h       V05 loc1      000h    02Dh
info.compStmtOffsetsCount    = 0
info.compStmtOffsetsImplicit = 0007h ( STACK_EMPTY NOP CALL_SITE )
*************** In fgFindBasicBlocks() for Qcom:ExtGetProgramBinarySource(int,int,byref,long)
weight= 10 : state   3 [ ldarg.0 ]
weight= 16 : state   4 [ ldarg.1 ]
weight= 35 : state   5 [ ldarg.2 ]
weight=-24 : state  39 [ pop ]
weight= 28 : state   6 [ ldarg.3 ]
weight=-11 : state  62 [ ldind.i4 ]
weight=  9 : state   8 [ ldloc.1 ]
weight= 28 : state  24 [ ldc.i4.1 ]
weight=-12 : state  76 [ add ]
weight= 79 : state  40 [ call ]
weight= 20 : state 199 [ stloc.0 -> ldloc.0 ]
weight= 28 : state   6 [ ldarg.3 ]
weight=159 : state 112 [ ldsfld ]
weight= 41 : state  32 [ ldc.i4.s ]
weight= 65 : state 128 [ ldelem.i ]
weight= 65 : state  41 [ calli ]
weight= 35 : state   5 [ ldarg.2 ]
weight= 12 : state   7 [ ldloc.0 ]
weight= 79 : state  40 [ call ]
weight= 60 : state  69 [ stind.ref ]
weight= 12 : state   7 [ ldloc.0 ]
weight= 79 : state  40 [ call ]
weight= 19 : state  42 [ ret ]
Marked V04 as a single def local
Marked V05 as a single def local
Jump targets:
  none
New Basic Block BB01 [0000] created.
BB01 [000..02D)

Inline candidate looks like a wrapper method.  Multiplier increased to 1.
Inline candidate callsite is hot.  Multiplier increased to 4.
Callsite has profile data: 1.  Multiplier limited to 16.8.
calleeNativeSizeEstimate=832
callsiteNativeSizeEstimate=175
benefit multiplier=16.8
threshold=2940
Native estimate for function size is within threshold for inlining 83.2 <= 294 (multiplier = 16.8)
CLFLG_MINOPT set for method Qcom:ExtGetProgramBinarySource(int,int,byref,long)
IL Code Size,Instr   45,  24, Basic Block count   1, Local Variable Num,Ref count   7, 11 for method Qcom:ExtGetProgramBinarySource(int,int,byref,long)
OPTIONS: opts.MinOpts() == true
Basic block list for 'Qcom:ExtGetProgramBinarySource(int,int,byref,long)'

-----------------------------------------------------------------------------------------------------------------------------------------
BBnum BBid ref try hnd                 weight    lp [IL range]     [jump]      [EH region]         [flags]
-----------------------------------------------------------------------------------------------------------------------------------------
BB01 [0000]  1                             1       [000..02D)        (return)
-----------------------------------------------------------------------------------------------------------------------------------------

*************** Starting PHASE Pre-import

*************** Finishing PHASE Pre-import

*************** Starting PHASE Profile incorporation
BBOPT set, but no profile data available (hr=80004001)

*************** Finishing PHASE Profile incorporation [no changes]

*************** Starting PHASE Importation
*************** In impImport() for Qcom:ExtGetProgramBinarySource(int,int,byref,long)

impImportBlockPending for BB01

Importing BB01 (PC=000) of 'Qcom:ExtGetProgramBinarySource(int,int,byref,long)'
    [ 0]   0 (0x000) ldarg.0
    [ 1]   1 (0x001) ldarg.1
    [ 2]   2 (0x002) ldarg.2
    [ 3]   3 (0x003) pop
    [ 2]   4 (0x004) ldarg.3
    [ 3]   5 (0x005) ldind.i4
    [ 3]   6 (0x006) ldloc.1
    [ 4]   7 (0x007) ldc.i4.1 1
    [ 5]   8 (0x008) add
    [ 4]   9 (0x009) call 0A000023
In Compiler::impImportCall: opcode is call, kind=0, callRetType is long, structSize is 0

lvaGrabTemp returning 7 (V07 tmp1) called for non-inline candidate call.


STMT00000 (IL 0x000...  ???)
               [000011] -A-XG-------              *  ASG       int
               [000010] D------N----              +--*  LCL_VAR   int    V07 tmp1
               [000004] *--XG-------              \--*  IND       int
               [000003] ------------                 \--*  LCL_VAR   long   V03 arg3

    [ 4]  14 (0x00e) stloc.0

STMT00001 (IL   ???...  ???)
               [000014] -AC-G-------              *  ASG       long
               [000013] D------N----              +--*  LCL_VAR   long   V04 loc0
               [000008] --C-G-------              \--*  CALL r2r_ind long   System.Runtime.InteropServices.Marshal.AllocHGlobal
               [000009] ------------ arg0            \--*  CAST      long <- int
               [000007] ------------                    \--*  ADD       int
               [000005] ------------                       +--*  LCL_VAR   int    V05 loc1
               [000006] ------------                       \--*  CNS_INT   int    1

    [ 3]  15 (0x00f) ldloc.0
    [ 4]  16 (0x010) ldarg.3
    [ 5]  17 (0x011) ldsfld 0400B09A
    [ 6]  22 (0x016) ldc.i4.s 102
    [ 7]  24 (0x018) ldelem.i
    [ 6]  25 (0x019) calli 11000113
lvaGrabTemp returning 8 (V08 tmp2) called for impImportIndirectCall.


STMT00002 (IL   ???...  ???)
               [000024] -ACXG-------              *  ASG       long
               [000023] D------N----              +--*  LCL_VAR   long   V08 tmp2
               [000022] --CXG-------              \--*  INDEX     long
               [000020] --CXG-------                 +--*  IND       ref
               [000019] --CXG-------                 |  \--*  ADD       byref
               [000017] --CXG-------                 |     +--*  CALL help r2r_ind byref  HELPER.CORINFO_HELP_READYTORUN_STATIC_BASE
               [000018] ------------                 |     \--*  CNS_INT   int    88 Fseq[EntryPoints]
               [000021] ------------                 \--*  CNS_INT   int    102

In Compiler::impImportCall: opcode is calli, kind=0, callRetType is void, structSize is 0

Inline a CALLI PINVOKE call from method Qcom:ExtGetProgramBinarySource(int,int,byref,long)

STMT00003 (IL   ???...  ???)
               [000026] --CXG-------              *  CALL ind unman void
               [000001] ------------ arg0         +--*  LCL_VAR   int    V01 arg1
               [000012] ------------ arg1         +--*  LCL_VAR   int    V07 tmp1
               [000015] ------------ arg2         +--*  LCL_VAR   long   V04 loc0
               [000016] ------------ arg3         +--*  LCL_VAR   long   V03 arg3
               [000025] ------------ calli tgt    \--*  LCL_VAR   long   V08 tmp2

    [ 1]  30 (0x01e) ldarg.2
    [ 2]  31 (0x01f) ldloc.0
    [ 3]  32 (0x020) call 06000002
In Compiler::impImportCall: opcode is call, kind=0, callRetType is ref, structSize is 0

    [ 3]  37 (0x025) stind.ref

STMT00004 (IL 0x01E...  ???)
               [000031] -ACXG-------              *  ASG       ref
               [000030] *------N----              +--*  IND       ref
               [000027] ------------              |  \--*  LCL_VAR   byref  V02 arg2
               [000029] --C-G-------              \--*  CALL r2r_ind ref    OpenTK.Graphics.BindingsBase.MarshalPtrToString
               [000028] ------------ arg0            \--*  LCL_VAR   long   V04 loc0

    [ 1]  38 (0x026) ldloc.0
    [ 2]  39 (0x027) call 0A000024
In Compiler::impImportCall: opcode is call, kind=0, callRetType is void, structSize is 0


STMT00005 (IL   ???...  ???)
               [000033] --C-G-------              *  CALL r2r_ind void   System.Runtime.InteropServices.Marshal.FreeHGlobal
               [000032] ------------ arg0         \--*  LCL_VAR   long   V04 loc0

    [ 1]  44 (0x02c) ret

STMT00006 (IL 0x02C...  ???)
               [000034] ------------              *  RETURN    void
To repro, add following arguments to the command line:
--singlemethodtypename "OpenTK.Graphics.ES11.GL+Qcom,OpenTK.Graphics" --singlemethodname "ExtGetProgramBinarySource" --singlemethodindex 12
Unhandled exception. ILCompiler.CodeGenerationFailedException: Code generation failed for method '[OpenTK.Graphics]OpenTK.Graphics.ES11.GL+Qcom.ExtGetProgramBinarySource(uint32,ShaderType,string&,int32*)'

@AndyAyersMS, could you please suggest someone from the JIT team to take a deeper look and help me understand whether we're doing something wrong in Crossgen2 or whether we've just started to hit a previously unseen corner case actually crashing the JIT compilation? I can confirm this trivially reproes with a freshly compiled Crossgen2 from runtime main.

Thanks

Tomas

@trylek
Copy link
Member

trylek commented Sep 15, 2021

/cc @dotnet/crossgen-contrib @dotnet/jit-contrib

@jkotas
Copy link
Member

jkotas commented Sep 15, 2021

This is same problem as dotnet/corert#8346

OpenTK.Graphics assembly contains invalid IL. crossgen2 does not tolerate completely invalid IL like this.

The problem was fixed by opentk/opentk#1286. The latest version of the OpenTK.Graphics package should have the fix.

@mangod9
Copy link
Member

mangod9 commented Sep 15, 2021

Ah, yeah looks like its the same problem. @ChrisKoebke could you please try with the latest version or opentk.graphics? Will close for now.

@mangod9 mangod9 closed this as completed Sep 15, 2021
@ChrisKoebke
Copy link
Author

Thanks a lot for your help! I'm currently using the latest available version from NuGet: OpenTK.Graphics v4.6.7.

What's weird about this is: I do have trimming enabled and am not using ExtGetProgramBinarySource anywhere in my project. Would it be possible to just discard this function entirely from the AOT compilation or is there some way to explicitly tell the AOT compiler to discard it?

It would also be really nice to have some more descriptive error messages in the Publish window. It currently just says "We couldn't determine the cause of this issue", so I assumed it has to be a R2R error. If it would say something like "We couldn't compile ExtGetProgramBinarySource from OpenTK.Graphics.dll, as it contains invalid IL instructions" that would've been really helpful to clarify that it's a problem with OpenTK and not with R2R.

Cheers,
Chris

@MichalStrehovsky
Copy link
Member

If you only set PublishTrimmed and nothing else, we only apply trimming to the framework libraries. Trimming wouldn't touch the OpenTK libraries. You need to either set the trim mode on the OpenTK.Graphics assembly individually to link, or set the default trimming action to link globally (<TrimmerDefaultAction>link</TrimmerDefaultAction> in csproj).

@NogginBops
Copy link

@ChrisKoebke if you would open an issue in the OpenTK repo with the issues you are currently having it would be a lot easier for us to track this issue as it seems like it's not been solved with opentk/opentk#1286

@NogginBops
Copy link

@jkotas Sorry for the ping. But it seems like this IL is the one that is generated after opentk/opentk#1286.
And I'm not so fluent in IL that I can spot where the invalid IL is in the code above, so I would really appreciate it if you could enlighten me.

Related to this topic, I've wondered if there is somewhere where one could read about what would constitute invalid IL, as from what I've seen the documentation is pretty sparse with details on what is actually allowed and what isn't. It could also be that I'm missing information and that I'm using the wrong mental model when thinking about IL stuff. Any resource you could recommend would be of help. 🙂

@jkotas
Copy link
Member

jkotas commented Oct 28, 2021

The problem is that there is extra item on the IL stack at the end of the method. Here is the IL annotated with the depth of the IL stack after each instruction:

      IL_0000:  ldarg.0
1
      IL_0001:  ldarg.1
2
      IL_0002:  ldarg.2
3
      IL_0003:  pop
2
      IL_0004:  ldarg.3
3
      IL_0005:  ldind.i4
3
      IL_0006:  ldloc.1
4
      IL_0007:  ldc.i4.1
5
      IL_0008:  add
4
      IL_0009:  call       native int [System.Private.CoreLib/*23000008*/]System.Runtime.InteropServices.Marshal/*0100001C*/::AllocHGlobal(native int) /* 0A000023 */
4
      IL_000e:  stloc.0
3
      IL_000f:  ldloc.0
4
      IL_0010:  ldarg.3
5
      IL_0011:  ldsfld     native int[] OpenTK.Graphics.ES11.GL/*02000A4C*/::EntryPoints /* 0400B09A */
6
      IL_0016:  ldc.i4.s   102
7
      IL_0018:  ldelem.i
6
      IL_0019:  calli      unmanaged stdcall void(uint32,int32,native int,int32*) /*11000113*/
1
      IL_001e:  ldarg.2
2
      IL_001f:  ldloc.0
3
      IL_0020:  call       string OpenTK.Graphics.BindingsBase/*0200001E*/::MarshalPtrToString(native int) /* 06000002 */
3
      IL_0025:  stind.ref
1
      IL_0026:  ldloc.0
2
      IL_0027:  call       void [System.Private.CoreLib/*23000008*/]System.Runtime.InteropServices.Marshal/*0100001C*/::FreeHGlobal(native int) /* 0A000024 */
1
      IL_002c:  ret

The doc that describes rules for valid IL is ECMA-335. ECMA-335 describes the rules for verifiable IL that are superset of the rules for valid IL, but that's not relevant in this case.

The rule violated in this case is "The evaluation stack for the current method shall be empty except for
the value to be returned." in chapter "III.3.57 ret – return from method".

@NogginBops
Copy link

Thanks a lot for your time! Really clear explanation.
I'll have a go at solving the problem so this might work soon @ChrisKoebke !

Also thanks for the link where I can read more about the issues.
It would be great if the AOT compiler had a clearer error message about what was going wrong here, which might be something to consider.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants