You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Arm64/Linux] b399444b fails under gcStress=0xC jitstress=1 #10800
corerun b399444b.exe
Assert failure(PID 7270 [0x00001c66], Thread: 7270 [0x1c66]):
!"About to FailFast. set ComPlus_AssertOnFailFast=0 if this is expected"
File: src/vm/jithelpers.cpp Line: 5157
Ok, figured one thing out. The a variant defines _65536 and so hits a type load exception (too many instance fields); b defines _65535 and so the type should be loadable.
Failure backtrace:
#0 0x0000ffffb77b3334 in DBG_DebugBreak () from /home/andya/repos/coreclr/bin/tests/Linux.arm64.Checked/Tests/Core_Root/libcoreclr.so
dotnet/coreclr#1 0x0000ffffb7728984 in DebugBreak () at /coreclr/src/pal/src/debug/debug.cpp:405
dotnet/coreclr#2 0x0000ffffb71ec67c in DbgAssertDialog (szFile=<optimized out>, iLine=<optimized out>, szExpr=<optimized out>) at /coreclr/src/utilcode/debug.cpp:737
dotnet/coreclr#3 0x0000ffffb738f36c in DoJITFailFast () at /coreclr/src/vm/jithelpers.cpp:5190
dotnet/coreclr#4 0x0000ffffb72c2354 in CrawlFrame::CheckGSCookies (this=<optimized out>) at /coreclr/src/vm/stackwalk.cpp:416
dotnet/coreclr#5 CrawlFrame::SetCurGSCookie (this=<optimized out>, pGSCookie=<optimized out>) at /coreclr/src/vm/stackwalk.cpp:433
dotnet/coreclr#6 StackFrameIterator::PreProcessingForManagedFrames (this=0xffffffffa830) at /coreclr/src/vm/stackwalk.cpp:3154
dotnet/coreclr#7 0x0000ffffb72bffc0 in StackFrameIterator::ProcessCurrentFrame (this=0xffffffffa830) at /coreclr/src/vm/stackwalk.cpp:2988
So we're stack walking at a GC stress breakin and the stack walk thinks there's a GS failure (a corrupted stack cookie).
Possibly related fact: unwind info for this method gets broken into two chunks. one covering from 0 to 0xFFFFC, the other from 0xFFFFC to 0x1ABFD0. So the offset at which GC is happening is right at this boundary.
Think what may be happening here is that when offset reaches 0xFFFFC the unwinder looks at the wrong unwind data segment and so doesn't properly recover the register state.
Unwind Info:
>> Start offset : 0x000000 (not in unwind data)
>> End offset : 0x0ffffc (not in unwind data)
Code Words : 1
Epilog Count : 0
E bit : 0
X bit : 0
Vers : 0
Function Length : 262143 (0x3ffff) Actual length = 1048572 (0x0ffffc)
---- Epilog scopes ----
No epilogs
---- Unwind codes ----
E1 set_fp; mov fp, sp
85 save_fplr_x dotnet/coreclr#5 (0x05); stp fp, lr, [sp, #-48]!
E4 end
E4 end
allocUnwindInfo(pHotCode=0x0000FFFF1C8F0078, pColdCode=0x0000000000000000, startOffset=0x0, endOffset=0xffffc, unwindSize=0x8, pUnwindBlock=0x00000000318AF926, funKind
=0 (main function))
Unwind Info:
>> Start offset : 0x0ffffc (not in unwind data)
>> End offset : 0x1abfd0 (not in unwind data)
Code Words : 1
Epilog Count : 1
E bit : 0
X bit : 0
Vers : 0
Function Length : 176117 (0x2aff5) Actual length = 704468 (0x0abfd4)
---- Epilog scopes ----
---- Scope 0
Epilog Start Offset : 176115 (0x2aff3) Actual offset = 704460 (0x0abfcc) Offset from main function begin = 1753032 (0x1abfc8)
Epilog Start Index : 2 (0x02)
---- Unwind codes ----
E5 end_c
E1 set_fp; mov fp, sp
---- Epilog start at index 2 ----
85 save_fplr_x dotnet/coreclr#5 (0x05); stp fp, lr, [sp, #-48]!
E4 end
unwindEmit: fragment dotnet/coreclr#2:
allocUnwindInfo(pHotCode=0x0000FFFF1C8F0078, pColdCode=0x0000000000000000, startOffset=0xffffc, endOffset=0x1abfd0, unwindSize=0xc, pUnwindBlock=0x000000003CC29A49, fu
nKind=0 (main function))
Arm64 unwind info allows 18 bits for length; each instr is 4 bytes, so total span is 2^20 bytes. So for longer functions multiple unwind records are needed. But only one will describe the prolog and hence the way to recover saved registers.
Guessing maybe EEJitManager::LazyGetFunctionEntry needs to be aware of these "Function Fragment" unwind records, and if the control PC lies within a fragment, then instead return the root unwind record?
Something similar should happen if there is a very large funclet. Not sure we have any cases where the funclet is so large it can't be covered by one unwind record; if not we should add one.
Note that we have the same function fragment stuff in arm32, and I remember the fragments there are smaller, so it's possible there's some code for arm32 that needs to be enabled for arm64, or perhaps the bug exists on arm32 as well.
The fix should rather be in the unwinder code. Looking at the Windows unwinder source, it seems it has been updated to support this scenario since we've ported its sources to coreclr.
The unwind now first checks if the UnwindType = (FunctionEntry->UnwindData & 3) is 3 and in case it is, it gets the parent record. The comment says:
// Unwind type 3 refers to a chained record. The top 30 bits of the
// unwind data contains the RVA of the parent pdata record.
The unwind code we have in coreclr just fails when the unwind type is set to 3.
Does our JIT generate the unwind type 3 for chained records?
is the runtime handling these fragmented records properly when it gets offsets in the fragmented part?
No, it isn't
does the debugger handle this properly (seems to use a different unwinder)?
It uses the same unwinder we use for Unix (where we use it for both debugger and managed code unwinding)
If the unwind spec changed since this was implemented, and (FunctionData->UnwindData & 3) means something besides (1) zero means Exception info RVA, and (2) non-zero means Packed unwind format,
Yes, that's what I was trying to point out. Value 3 now means chained unwind records (for both compact and full unwind). The parent record never contains 3 there.
@AndyAyersMS The JIT has COMPlus_JitSplitFunctionSize which you can set to some (small-ish) value to force creating more fragments. We should probably add some testing of this to the JIT stress mix.
See UnwindInfo::Split(). It has the "helpful" comment (you're welcome):
// ARM64 has very similar limitations, except functions can be up to 1MB. TODO-ARM64-Bug?: make sure this works!
Yes enabling some kind of split stress seems prudent to force us down these paths more often and with more variety. It is somewhat of painful to work with huge methods (the jit dump was 1.7GB).
Flag is a 2-bit field that indicates how to interpret the remaining 30 bits of the second .pdata word. If Flag is 0, then the remaining bits form an Exception Information RVA (with the low two bits implicitly 0). If Flag is non-zero, then the remaining bits form a Packed Unwind Data structure.
Thanks @AndyAyersMS for the investigation and testing. I was thinking about it and since (unless I miss something) we need this fix for Windows ARM64 too, the fix cannot be in the unwinder code that we have in coreclr (as it would then be used for Linux / debugger only). So it seems to me that your fix is actually at a proper place. The only thing I would do is to extract the loop that iterates over the fragments into a separate function and use it both in your change and in the IJitManager::GetFuncletStartAddress. The IJitManager::GetFuncletStartAddress contains extra getting of the funcletStartAddress in each iteration, but it is actually not needed and getting it after the loop would work too.
Would you mind making this slight modification to your change and send out a PR with that?
Activity
sdmaclea commentedon Jul 31, 2018
@RussKeldorph
Originally reported in #10449
AndyAyersMS commentedon Jan 18, 2019
I'll investigate.
AndyAyersMS commentedon Jan 22, 2019
This has failed for the past 19 weeks (via cross checked)...
I can repro, so will start debugging.
A couple of odd things to follow up:
a) version seemingly should produce the same IL, butaruns just fineAndyAyersMS commentedon Jan 22, 2019
Ok, figured one thing out. The
avariant defines _65536 and so hits a type load exception (too many instance fields);bdefines _65535 and so the type should be loadable.Failure backtrace:
So we're stack walking at a GC stress breakin and the stack walk thinks there's a GS failure (a corrupted stack cookie).
AndyAyersMS commentedon Jan 23, 2019
Assert is a failing cookie check, looks like
pCurGSCookieis wrong or the stack location it points to is corrupted:Fails here:
https://github.com/dotnet/coreclr/blob/b9e88989458e24fa9764e045917b141e3338eae7/src/vm/stackwalk.cpp#L403-L418
The frame being processed seems to be
possibly more than a coincidence that the offset is very close to 2^20...? Cookie location in the frame comes from GC info, so will look at that next.
AndyAyersMS commentedon Jan 23, 2019
Possibly related fact: unwind info for this method gets broken into two chunks. one covering from 0 to 0xFFFFC, the other from 0xFFFFC to 0x1ABFD0. So the offset at which GC is happening is right at this boundary.
AndyAyersMS commentedon Jan 23, 2019
Think what may be happening here is that when offset reaches 0xFFFFC the unwinder looks at the wrong unwind data segment and so doesn't properly recover the register state.
AndyAyersMS commentedon Jan 23, 2019
Arm64 unwind info allows 18 bits for length; each instr is 4 bytes, so total span is 2^20 bytes. So for longer functions multiple unwind records are needed. But only one will describe the prolog and hence the way to recover saved registers.
Guessing maybe
EEJitManager::LazyGetFunctionEntryneeds to be aware of these "Function Fragment" unwind records, and if the control PC lies within a fragment, then instead return the root unwind record?Something similar should happen if there is a very large funclet. Not sure we have any cases where the funclet is so large it can't be covered by one unwind record; if not we should add one.
cc @janvorli @BruceForstall
janvorli commentedon Jan 23, 2019
@AndyAyersMS let me take a look.
AndyAyersMS commentedon Jan 23, 2019
Here's what I'm trying: Arm64FunctionFragmentFix.
BruceForstall commentedon Jan 23, 2019
Note that we have the same function fragment stuff in arm32, and I remember the fragments there are smaller, so it's possible there's some code for arm32 that needs to be enabled for arm64, or perhaps the bug exists on arm32 as well.
janvorli commentedon Jan 23, 2019
The fix should rather be in the unwinder code. Looking at the Windows unwinder source, it seems it has been updated to support this scenario since we've ported its sources to coreclr.
The unwind now first checks if the UnwindType = (FunctionEntry->UnwindData & 3) is 3 and in case it is, it gets the parent record. The comment says:
The unwind code we have in coreclr just fails when the unwind type is set to 3.
Does our JIT generate the unwind type 3 for chained records?
BruceForstall commentedon Jan 23, 2019
Shouldn't EEJitManager::LazyGetFunctionEntry call IJitManager::GetFuncletStartAddress to find the "host" record for the function/funclet?
Or maybe the caller; depends on the use, I guess.
AndyAyersMS commentedon Jan 23, 2019
The only thing I see us doing is setting the
Fbit (and perhaps not properly for arm64, maybe this is the bug?)https://github.com/dotnet/coreclr/blob/a0f81f59a7beb7120d3147c1547ef8ec1f05e0ae/src/jit/unwindarm.cpp#L1492-L1496
4 remaining items
janvorli commentedon Jan 23, 2019
No, it isn't
It uses the same unwinder we use for Unix (where we use it for both debugger and managed code unwinding)
Yes, that's what I was trying to point out. Value 3 now means chained unwind records (for both compact and full unwind). The parent record never contains 3 there.
BruceForstall commentedon Jan 23, 2019
@AndyAyersMS The JIT has COMPlus_JitSplitFunctionSize which you can set to some (small-ish) value to force creating more fragments. We should probably add some testing of this to the JIT stress mix.
See UnwindInfo::Split(). It has the "helpful" comment (you're welcome):
:-)
AndyAyersMS commentedon Jan 23, 2019
Saw that comment....
Yes enabling some kind of split stress seems prudent to force us down these paths more often and with more variety. It is somewhat of painful to work with huge methods (the jit dump was 1.7GB).
BruceForstall commentedon Jan 23, 2019
@janvorli The published arm64 unwind spec doesn't seem to mention what you're describing: https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling?view=vs-2017.
AndyAyersMS commentedon Jan 23, 2019
I don't know if it is related but
sos ClrStackcrashes when you're broken in at this offset. So we should make sure that works too.janvorli commentedon Jan 23, 2019
@BruceForstall the Windows unwinder is handling it that way, so I guess the doc is out of date.
AndyAyersMS commentedon Jan 24, 2019
FYI the provisional changes to
LazyGetFunctionEntryfix this particular issue.@janvorli does it make sense for you to take this over?
Or, I'm happy to work up a proper fix if you give me some pointers.
janvorli commentedon Jan 24, 2019
Thanks @AndyAyersMS for the investigation and testing. I was thinking about it and since (unless I miss something) we need this fix for Windows ARM64 too, the fix cannot be in the unwinder code that we have in coreclr (as it would then be used for Linux / debugger only). So it seems to me that your fix is actually at a proper place. The only thing I would do is to extract the loop that iterates over the fragments into a separate function and use it both in your change and in the IJitManager::GetFuncletStartAddress. The IJitManager::GetFuncletStartAddress contains extra getting of the funcletStartAddress in each iteration, but it is actually not needed and getting it after the loop would work too.
Would you mind making this slight modification to your change and send out a PR with that?
AndyAyersMS commentedon Jan 25, 2019
Sure -- should have a PR ready before too long.
Fix finding entry point unwind record for a method with fragmented un…
Fix finding entry point unwind record for a method with fragmented un… (