Recursive SIGSEGV question
Segher Boessenkool
segher@kernel.crashing.org
Mon Mar 25 18:56:00 GMT 2019
On Mon, Mar 25, 2019 at 09:55:56PM +0800, Xi Ruoyao wrote:
> On 2019-03-25 13:06 +0000, Jonny Grant wrote:
> > I built & ran with the Sanitizer, it seems it's also stack overflow
> > within the operator new()
> >
> > I had thoughts GCC would generate code that monitored the stack size and
> > aborted with a clear message when the stack size was exceeded. Looked
> > online, and it doesn't seem to be the case.
>
> Impossible. We can't distinguish "stack overflow" with other segmentation
> faults. For example
>
> int foo() {volatile char p[10000000]; p[0] = 1;}
>
> and
>
> int foo() {
> volatile char a;
> (&a)[-9999999] = 1;
> }
>
> may be compiled to exactly same machine code. Now which one is a stack
> overflow?
The second one is undefined behaviour so it can do whatever you want.
That includes reporting it as a stack overflow. There in general is no
way to fix this, it has nothing to do with the problem at hand.
Segher
More information about the Gcc-help
mailing list