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

[NativeAOT] System.NotImplementedException: CORINFO_HELP_GETSYNCFROMCLASSHANDLE #77093

Closed
Cyl18 opened this issue Oct 16, 2022 · 3 comments · Fixed by #94203
Closed

[NativeAOT] System.NotImplementedException: CORINFO_HELP_GETSYNCFROMCLASSHANDLE #77093

Cyl18 opened this issue Oct 16, 2022 · 3 comments · Fixed by #94203

Comments

@Cyl18
Copy link
Contributor

Cyl18 commented Oct 16, 2022

Description

System.NotImplementedException: CORINFO_HELP_GETSYNCFROMCLASSHANDLE
Code generation failed for method '[GammaLibrary]GammaLibrary.Configuration`1<System.__Canon>.Save()'

Code of Save() is

https://github.com/Cyl18/GammaLibrary/blob/e6f41509f6d526b6647960d65bb09c97a30383d6/GammaLibrary/Configuration.cs#L48

Reproduction Steps

  1. clone https://github.com/TRKS-Team/WFBot/tree/nativeAOT
  2. run build-wfbot-ci.bat

content of build-wfbot-ci.bat:

dotnet publish WFBot -o out/WFBotWindowsS -r win-x86 --self-contained true -c "Linux Release" -p:PublishSingleFile=true -p:PublishReadyToRun=true /p:IncludeNativeLibrariesForSelfExtract=true

Expected behavior

successfully compile

Actual behavior

.NET 6 logs
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error : Error
: One or more errors occurred. (Code generation failed for method '[GammaLibrary]GammaLibrary.Configuration`1<System.__
Canon>.Save()') [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error : Syste
m.AggregateException: One or more errors occurred. (Code generation failed for method '[GammaLibrary]GammaLibrary.Confi
guration`1<System.__Canon>.Save()') [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :  --->
 ILCompiler.CodeGenerationFailedException: Code generation failed for method '[GammaLibrary]GammaLibrary.Configuration`
1<System.__Canon>.Save()' [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :  --->
 System.NotImplementedException: CORINFO_HELP_GETSYNCFROMCLASSHANDLE [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot
.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 Internal.JitInterface.CorInfoImpl.GetHelperFtnUncached(CorInfoHelpFunc ftnNum) [C:\Users\cyl18\Documents\GitHub\WFBot\
WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 Internal.JitInterface.CorInfoImpl.getHelperFtn(CorInfoHelpFunc ftnNum, Void*& ppIndirection) [C:\Users\cyl18\Documents
\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 Internal.JitInterface.CorInfoImpl._getHelperFtn(IntPtr thisHandle, IntPtr* ppException, CorInfoHelpFunc ftnNum, Void**
 ppIndirection) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    --
- End of inner exception stack trace --- [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 Internal.JitInterface.CorInfoImpl.CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, MethodIL methodIL) [C:\
Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 Internal.JitInterface.CorInfoImpl.CompileMethod(MethodWithGCInfo methodCodeNodeNeedingCode, Logger logger) [C:\Users\c
yl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 ILCompiler.ReadyToRunCodegenCompilation.<ComputeDependencyNodeDependencies>b__36_0(DependencyNodeCore`1 dependency) [C
:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 System.Threading.Tasks.Parallel.<>c__DisplayClass33_0`2.<ForEachWorker>b__0(Int32 i) [C:\Users\cyl18\Documents\GitHub\
WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boo
lean& replicationDelegateYieldedBeforeCompletion) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error : --- E
nd of stack trace from previous location --- [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boo
lean& replicationDelegateYieldedBeforeCompletion) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 System.Threading.Tasks.TaskReplicator.Replica.Execute() [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    --
- End of inner exception stack trace --- [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction`1 action, ParallelOptions options, Boolean st
opOnFirstFailure) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOpti
ons, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally) [C:\Users\cy
l18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error : --- E
nd of stack trace from previous location --- [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationT
oken cancelToken, Exception otherException) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOpti
ons, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally) [C:\Users\cy
l18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    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) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, A
ction`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEver
ything, Func`1 localInit, Action`1 localFinally) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body)
 [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 ILCompiler.ReadyToRunCodegenCompilation.ComputeDependencyNodeDependencies(List`1 obj) [C:\Users\cyl18\Documents\GitHub
\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() [C:\Users\cyl18\Documents\GitHub\WFBo
t\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.
csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String
compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, CompilerTypeSystemContext t
ypeSystemContext) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 ILCompiler.Program.Run(String[] args) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(464,5): error :    at
 ILCompiler.Program.Main(String[] args) [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
.NET 7 logs
C:\Program Files\dotnet\sdk\7.0.100-rc.2.22477.23\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(465,5):
 error : Error: One or more errors occurred. (Code generation failed for method '[WFBot]WFBot.Utils.Configuration`1<Sys
tem.__Canon>.get_Instance()') [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\7.0.100-rc.2.22477.23\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(465,5):
 error : System.AggregateException: One or more errors occurred. (Code generation failed for method '[WFBot]WFBot.Utils
.Configuration`1<System.__Canon>.get_Instance()') [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\7.0.100-rc.2.22477.23\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(465,5):
 error :  ---> ILCompiler.CodeGenerationFailedException: Code generation failed for method '[WFBot]WFBot.Utils.Configur
ation`1<System.__Canon>.get_Instance()' [C:\Users\cyl18\Documents\GitHub\WFBot\WFBot\WFBot.csproj]
C:\Program Files\dotnet\sdk\7.0.100-rc.2.22477.23\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.CrossGen.targets(465,5):
 error :  ---> System.NotImplementedException: CORINFO_HELP_GETSYNCFROMCLASSHANDLE [C:\Users\cyl18\Documents\GitHub\WFB
ot\WFBot\WFBot.csproj]

Regression?

No response

Known Workarounds

#77093 (comment)

Configuration

.NET 6 on windows
tried .NET 7, won't work

Other information

maybe #68278 is related to this?

@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.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 16, 2022
@Suchiman
Copy link
Contributor

I think the issue is [MethodImpl(MethodImplOptions.Synchronized)], try using an explicit static lock object and lock (...) on that instead as a workaround

@MichalStrehovsky MichalStrehovsky added this to the 8.0.0 milestone Oct 27, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Oct 27, 2022
@MichalStrehovsky
Copy link
Member

  • Hittable for static methods on generic types with [MethodImpl(MethodImplOptions.Synchronized)]
  • CORINFO_HELP_GETSYNCFROMCLASSHANDLE is not implemented for ReadyToRun either, which is how this was missed.
  • We'd also want to implement CORINFO_HELP_GETCLASSFROMMETHODPARAM to handle the generic method case.
  • CORINFO_HELP_GETCLASSFROMMETHODPARAM is not really supportable on NativeAOT (can't get from a method to its owning class). We'd really want this in the form of a ReadyToRun helper. This means some small amount of JIT work as well.

@MichalStrehovsky MichalStrehovsky modified the milestones: 8.0.0, 9.0.0 Jul 11, 2023
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this issue Oct 31, 2023
Fixes dotnet#77093.

As I was looking at the bug, I realized it got miscategorized as native AOT, but the customer filed it for ReadyToRun. The bug is in both native AOT and ReadyToRun. I'm fixing it for both.

We clearly didn't have any pre-existing test coverage, but as I was looking around the test tree, getclassfrommethodparam.cs was obviously testing this. For unexplained reasons, the Synchronized part got commented out. When I compared the file with the original in TFS at `$/DevDiv/FX/Feature/NetFXDev1/QA/CLR/testsrc/jit/Generics/Fields/getclassfrommethodparam.cs`, the commented out line is not commented out. So I'm fixing it. I've also added dedicated native aot test because this has dependency analysis implications that we need to be careful about.
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Oct 31, 2023
MichalStrehovsky added a commit that referenced this issue Oct 31, 2023
Fixes #77093.

As I was looking at the bug, I realized it got miscategorized as native AOT, but the customer filed it for ReadyToRun. The bug is in both native AOT and ReadyToRun. I'm fixing it for both.

We clearly didn't have any pre-existing test coverage, but as I was looking around the test tree, getclassfrommethodparam.cs was obviously testing this. For unexplained reasons, the Synchronized part got commented out. When I compared the file with the original in TFS at `$/DevDiv/FX/Feature/NetFXDev1/QA/CLR/testsrc/jit/Generics/Fields/getclassfrommethodparam.cs`, the commented out line is not commented out. So I'm fixing it. I've also added dedicated native aot test because this has dependency analysis implications that we need to be careful about.
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Oct 31, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Dec 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants