https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91543

            Bug ID: 91543
           Summary: Handling stack overflow more sensibly
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tkoenig at gcc dot gnu.org
  Target Milestone: ---

I've just been bitten by a strange segfault, which turned out to be
due to insufficient stack space with -Ofast (running nf from the
Polyhedron benchmarks).

We really need a sensible error message when that happens.
"Insufficient stack space, aborting\n" would already be enough.

Of course, not every segmentation violation is a stack overflow :-|

So, a strategy could be:

On startup, prepare a heap buffer with a sensible error message.
Also, stash away the starting address of the stack, its size and
other pertinent information, and set up a signal handler for SIGSEGV
using sigalstack().

On receiving a SIGSEGV, we could check if the segfaulting address
is indeed near the end of the stack, and if that is the case,
just do a write(2,...) with our prepared error message and exit.
Otherwise, just do the normal thing (usually, abort).

We could also increase the stack size, to avoid hitting that
particular error too soon.

What do people think?

Reply via email to