Description
Description
A stack overflow can be caused while logging a warning in a complex scenario involving compiler generated code. In my case, IL code gen was also involved.
I hit this error while running some of our tests using Unity's latest UnityLinker
which is admittedly only using https://github.com/dotnet/linker/tree/release/7.0 and not the latest illink code in the runtime repo. However, I've gone over the diff of the offending code as well as the history and I don't see any reason to believe this issues has been addressed.
The scenario is:
In GetCompilerGeneratedStateForType, the call to LogWarning starts things off. From there it's
-> MessageContainer.CreateWarningMessage
-> context.IsWarningSuppressed
-> Suppressions.IsSuppressed
-> TryGetOwningMethodForCompilerGeneratedMember
-> GetCompilerGeneratedStateForType.
Rinse & Repeat until boom.
The repro code I have is fairly complex and I don't have a standalone repro.
Somehow it seems like the cycle needs to be broken.
I played around with a fix 2d2b36a and it does work for the scenario I'm hitting. But...
-
There are other
LogWarning
calls inGetCompilerGeneratedStateForType
and I'm not sure if the fix I did should be used there as well? -
GetGeneratedTypeAttributes also calls GetCompilerGeneratedStateForType which makes me wonder if it could also be vulnerable to a stack overflow.
Reproduction Steps
I don't have a reproduction case. Here is the information I have.
The LogWarning that is leads to the stack overflow is this one
When LogWarning
is called, the state of the interesting locals is
stateMachineType = Unity.DataFlowGraph.PerformanceTests.SimpleBurstStateMachinesPerformanceTests/<<Unit>g__Test|1_0>d
alreadyAssociatedMethod = Unity.DataFlowGraph.Routine Unity.DataFlowGraph.PerformanceTests.SimpleBurstStateMachinesPerformanceTests::<Unit>g__Test|1_0(Unity.DataFlowGraph.Routine)
method = Unity.DataFlowGraph.Routine Unity.DataFlowGraph.PerformanceTests.SimpleBurstStateMachinesPerformanceTests::<Unit>g__Test|1_0$BurstManaged(Unity.DataFlowGraph.Routine)
And here is the il of the assembly LogWarningStackOverflow.txt
Expected behavior
ILLink issues a warning and completes successfully.
Actual behavior
The linker crashes with FullCrashStack.txt
Regression?
Technically, yes this is a regression. Our older version of UnityLinker does not crash on this code. However, our old linker is based on a version of Mono.Linker
that is so old it doesn't have CompilerGeneratedState.cs
so this issue has been around for awhile.
Known Workarounds
Don't trigger the LogWarning call.
Configuration
No response
Other information
No response
Metadata
Metadata
Assignees
Type
Projects
Status