runtime icon indicating copy to clipboard operation
runtime copied to clipboard

[x64/Linux] Segmentation fault in infinite inheritance

Open Buyduck opened this issue 9 years ago • 9 comments

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

Buyduck avatar Jan 25 '17 18:01 Buyduck

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?

stephentoub avatar Jan 25 '17 19:01 stephentoub

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?

Buyduck avatar Jan 26 '17 07:01 Buyduck

@janvorli, is this behaving as you'd expect?

stephentoub avatar Jan 26 '17 13:01 stephentoub

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 avatar Jan 26 '17 14:01 janvorli

@janvorli One solution is to use an alternate signal stack.

DemiMarie avatar Feb 06 '17 21:02 DemiMarie

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

janvorli avatar Feb 06 '17 21:02 janvorli

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 avatar Feb 21 '17 09:02 christianhuening

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

janvorli avatar Feb 21 '17 13:02 janvorli

Reportint fixed by dotnet/coreclr#9650

janvorli avatar Feb 22 '17 22:02 janvorli