public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Do not crash on empty epilogues
@ 2011-01-03 23:33 Ulrich Weigand
  2011-01-04  1:35 ` Bernd Schmidt
  0 siblings, 1 reply; 3+ messages in thread
From: Ulrich Weigand @ 2011-01-03 23:33 UTC (permalink / raw)
  To: gcc-patches

Hello,

GCC now crashes on the SPU when compiling functions with the "naked"
attribute.  The problem is this code in thread_prologue_and_epilogue_insns:

        seq = gen_epilogue ();
        emit_jump_insn (seq);

Naked functions have no epilogue, and thus gen_epilogue returns NULL.
However, emit_jump_insn crashes on a NULL input (as opposed to emit_insn
b.t.w., which is why this problem doesn't show up for the prologue).

This used to be OK since the SPU gen_epilogue would always generate
at least a NOTE.  But this was removed by Andrew Pinksi to fix PR 43156.

A couple of other targets that support naked functions work around this
problem by generating some dummy insn (e.g. an UNSPEC_VOLATILE that
expands to no assembler code).  But this seems a bit silly to me; GCC
common code simply shouldn't crash on empty epilogues.

The following patch fixes the crash for me.

Tested on spu-elf.

OK for mainline?

Bye,
Ulrich

ChangeLog:

	* function.c (thread_prologue_and_epilogue_insns): Do not crash
	on empty epilogue sequences.

Index: gcc/function.c
===================================================================
*** gcc/function.c	(revision 168294)
--- gcc/function.c	(working copy)
*************** thread_prologue_and_epilogue_insns (void
*** 5461,5467 ****
        start_sequence ();
        epilogue_end = emit_note (NOTE_INSN_EPILOGUE_BEG);
        seq = gen_epilogue ();
!       emit_jump_insn (seq);
  
        /* Retain a map of the epilogue insns.  */
        record_insns (seq, NULL, &epilogue_insn_hash);
--- 5461,5468 ----
        start_sequence ();
        epilogue_end = emit_note (NOTE_INSN_EPILOGUE_BEG);
        seq = gen_epilogue ();
!       if (seq)
! 	emit_jump_insn (seq);
  
        /* Retain a map of the epilogue insns.  */
        record_insns (seq, NULL, &epilogue_insn_hash);
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] Do not crash on empty epilogues
  2011-01-03 23:33 [patch] Do not crash on empty epilogues Ulrich Weigand
@ 2011-01-04  1:35 ` Bernd Schmidt
  2011-01-04 12:39   ` Ulrich Weigand
  0 siblings, 1 reply; 3+ messages in thread
From: Bernd Schmidt @ 2011-01-04  1:35 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: gcc-patches

On 01/04/2011 12:22 AM, Ulrich Weigand wrote:
> GCC now crashes on the SPU when compiling functions with the "naked"
> attribute.  The problem is this code in thread_prologue_and_epilogue_insns:
> 
>         seq = gen_epilogue ();
>         emit_jump_insn (seq);
> 
> Naked functions have no epilogue, and thus gen_epilogue returns NULL.
> However, emit_jump_insn crashes on a NULL input (as opposed to emit_insn
> b.t.w., which is why this problem doesn't show up for the prologue).
> 
> This used to be OK since the SPU gen_epilogue would always generate
> at least a NOTE.  But this was removed by Andrew Pinksi to fix PR 43156.
> 
> A couple of other targets that support naked functions work around this
> problem by generating some dummy insn (e.g. an UNSPEC_VOLATILE that
> expands to no assembler code).  But this seems a bit silly to me; GCC
> common code simply shouldn't crash on empty epilogues.
> 
> The following patch fixes the crash for me.
> 
> Tested on spu-elf.
> 
> OK for mainline?

Ok. It would be nice to also avoid emitting the NOTE_INSN_EPILOGUE_BEG;
such a change is ok too if you want to make it. The same thing could
also be done for sibcall epilogues.

Another way to fix it in the backend is to ensure HAVE_epilogue is false
if the epilogue would be empty.


Bernd

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] Do not crash on empty epilogues
  2011-01-04  1:35 ` Bernd Schmidt
@ 2011-01-04 12:39   ` Ulrich Weigand
  0 siblings, 0 replies; 3+ messages in thread
From: Ulrich Weigand @ 2011-01-04 12:39 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: gcc-patches

Bernd Schmidt wrote:
> On 01/04/2011 12:22 AM, Ulrich Weigand wrote:
> > A couple of other targets that support naked functions work around this
> > problem by generating some dummy insn (e.g. an UNSPEC_VOLATILE that
> > expands to no assembler code).  But this seems a bit silly to me; GCC
> > common code simply shouldn't crash on empty epilogues.
> 
> Ok. It would be nice to also avoid emitting the NOTE_INSN_EPILOGUE_BEG;
> such a change is ok too if you want to make it. The same thing could
> also be done for sibcall epilogues.
> 
> Another way to fix it in the backend is to ensure HAVE_epilogue is false
> if the epilogue would be empty.

I've checked in the original patch now, as the minimal change to fix
the regression.  Any further changes can probably wait until we're
back in stage 1 ...

Thanks,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-04 12:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-03 23:33 [patch] Do not crash on empty epilogues Ulrich Weigand
2011-01-04  1:35 ` Bernd Schmidt
2011-01-04 12:39   ` Ulrich Weigand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).