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

--- Comment #7 from Peter Bergner <bergner at gcc dot gnu.org> ---
(In reply to Peter Bergner from comment #6)
> (In reply to Peter Bergner from comment #5)
> > bergner@kubota:COBOL$ ./a.out 
> > Hello, world!
> > Segmentation fault (core dumped)
> 
> The return address at the beginning of main ends up not being the address we
> end up returning to, which leads to the segv, so it looks like the saved
> return address on the stack is getting corrupted.
So this test runs fine if I compile with -O1 or greater and SEGVs if I compile
with -O0.  In the -O0 case, main's return value stack slot is overwritten by
some spill code in the hello$world function.

The issue seems to be we're not allocating enough stack space, but the spill
code we emit seems to assume we have, and so we overwrite our callers stack
frame.  I think we're only getting lucky in the -O1 and greater case, because
this simple test case doesn't generate any spill code.

This particular bug is unrelated to this bugzilla report, so I'll open a
separate bug to track this.

Reply via email to