[x64/Linux] Segmentation fault in infinite inheritance
Segmentation fault:
$ ~/coreclr-demo/coreclr-demo25012017/corerun test.exe
Segmentation fault (core dumped)
While running such source:
public class Grand
{
public class Son : Grand {}
Son S = new Son();
}
public class Test
{
public static void Main()
{
Grand G = new Grand();
}
}
Visual Studio throwing System.StackOverflowException on this code
Visual Studio throwing System.StackOverflowException on this code
This is expected: the code overflows the stack.
Is the concern then just that there isn't a better error message output when the stack overflow causes the process to crash?
Thanks for response! Usually, if there is an error in managed code - corerun throws exception, which shows exception type and line, that raises it. But with this sample corerun crashed and didn't show the reason of this crash. Is this expected behavior for corerun?
@janvorli, is this behaving as you'd expect?
There are cases where the stack overflow cannot be handled in a nice way. When we physically get out of stack, the SIGSEGV handler cannot even be called by the kernel, since there is no stack space for executing it. And even if the stack overflow is detected by probing in the jitted code and there is some stack left, we still just display a simple message in the SIGSEGV handler ("Process is terminating due to StackOverflowException."), because we don't really know if we would have enough space to execute another managed code that is needed to build the stack trace. I have issue dotnet/runtime#4475 to investigate a possibility to make sure we can display the simple message even in case we got out of stack and have not just probed for the stack space.
@janvorli One solution is to use an alternate signal stack.
@DemiMarie I know, that's what I've described as a way to solve it in the issue dotnet/runtime#4475. But it would bring in an additional complexity for non-stack overflow SIGSEGV handling like switching the stack back to the original thread's stack, creating a helper stack frame so that the stack walking would work etc. I have not dismissed it completely yet, but I am still not convinced it is worth the little difference between the process failing with sigsegv and the process showing the stack overflow message and then failing with abort.
Hm just to understand: If we see our code failing with a SIGSEGV, it might well be a StackOverflowException internally? Because we have that issue in a high-performance, high-memory application and were looking for unsafe code or libraries we use, that could cause a SIGSEGV, but couldn't find any up to now.
@christianhuening yes, you are right. Stack overflow is manifested as SIGSEGV on Unix - the processor tries to write or read something from the stack, but the location is in a range that's out of the stack and so it is not mapped to any physical memory -> SIGSEGV. I am currently finalizing change dotnet/coreclr#9650 that runs the SIGSEGV handler on a separate stack, so it will be able to report stack overflow in all cases.
Reportint fixed by dotnet/coreclr#9650