public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC EH unwinding bug and libjava calling std::terminate ()
@ 2009-03-27 14:28 Jan Hubicka
  2009-03-27 18:14 ` Andrew Haley
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Hubicka @ 2009-03-27 14:28 UTC (permalink / raw)
  To: gcc, java

Hi,
current mainline is buggy in EH unwinding effectivly ignoring
MUST_NOT_THROW regions when reached via RESX from local handlers.
See http://gcc.gnu.org/ml/gcc-patches/2009-03/msg01285.html for details.

Unfortunately this patch causes bootstrap failure when building libjava,
because std::terminate() is now called.  The call comes from
run_proxy in natVMProxy.cc where we have cleanup code calling
destructor of:

_Jv_InterpFrame frame_desc (self->self, thread, proxyClass,
                              NULL, frame_proxy);

Now the desctuctor is pretty simple but because of:
'if a destructor called during stack unwinding exits with an exception,
std::terminate is called'

and because we use -fnon-call-excpetion and destructor is accessing
memory, we keep MUST_NOT_THROW terminate () call accessible
because after inlining the destructor, cleanup might unwind up
to that MUST_NOT_THROW.

Questio is how to fix this situation? Shall we link with C++ runtime,
or use -fno-non-call-exceptions to build this file or somehow restruture
code to avoid this case?

Honza

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

* Re: GCC EH unwinding bug and libjava calling std::terminate ()
  2009-03-27 14:28 GCC EH unwinding bug and libjava calling std::terminate () Jan Hubicka
@ 2009-03-27 18:14 ` Andrew Haley
  2009-03-27 18:28   ` Jan Hubicka
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Haley @ 2009-03-27 18:14 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc, java

Jan Hubicka wrote:

> current mainline is buggy in EH unwinding effectivly ignoring
> MUST_NOT_THROW regions when reached via RESX from local handlers.
> See http://gcc.gnu.org/ml/gcc-patches/2009-03/msg01285.html for details.
> 
> Unfortunately this patch causes bootstrap failure when building libjava,
> because std::terminate() is now called.  The call comes from
> run_proxy in natVMProxy.cc where we have cleanup code calling
> destructor of:
> 
> _Jv_InterpFrame frame_desc (self->self, thread, proxyClass,
>                               NULL, frame_proxy);
> 
> Now the desctuctor is pretty simple but because of:
> 'if a destructor called during stack unwinding exits with an exception,
> std::terminate is called'
> 
> and because we use -fnon-call-excpetion and destructor is accessing
> memory, we keep MUST_NOT_THROW terminate () call accessible
> because after inlining the destructor, cleanup might unwind up
> to that MUST_NOT_THROW.
> 
> Questio is how to fix this situation? Shall we link with C++ runtime,

Please don't.

> or use -fno-non-call-exceptions

No, because it might segfault, and we need to catch it.

> to build this file or somehow restruture
> code to avoid this case?

/* Gimplify a MUST_NOT_THROW_EXPR.  */

static enum gimplify_status
gimplify_must_not_throw_expr (tree *expr_p, gimple_seq *pre_p)
{
  tree stmt = *expr_p;
  tree temp = voidify_wrapper_expr (stmt, NULL);
  tree body = TREE_OPERAND (stmt, 0);
  tree termination;

  if (pragma_java_exceptions)
    termination = terminate_node;
  else
    termination = abort_node;

  stmt = build_gimple_eh_filter_tree (body, NULL_TREE,
				      build_call_n (termination, 0));



Andrew.

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

* Re: GCC EH unwinding bug and libjava calling std::terminate ()
  2009-03-27 18:14 ` Andrew Haley
@ 2009-03-27 18:28   ` Jan Hubicka
  2009-03-27 18:39     ` Andrew Haley
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Hubicka @ 2009-03-27 18:28 UTC (permalink / raw)
  To: Andrew Haley; +Cc: Jan Hubicka, gcc, java

> Jan Hubicka wrote:
> 
> > current mainline is buggy in EH unwinding effectivly ignoring
> > MUST_NOT_THROW regions when reached via RESX from local handlers.
> > See http://gcc.gnu.org/ml/gcc-patches/2009-03/msg01285.html for details.
> > 
> > Unfortunately this patch causes bootstrap failure when building libjava,
> > because std::terminate() is now called.  The call comes from
> > run_proxy in natVMProxy.cc where we have cleanup code calling
> > destructor of:
> > 
> > _Jv_InterpFrame frame_desc (self->self, thread, proxyClass,
> >                               NULL, frame_proxy);
> > 
> > Now the desctuctor is pretty simple but because of:
> > 'if a destructor called during stack unwinding exits with an exception,
> > std::terminate is called'
> > 
> > and because we use -fnon-call-excpetion and destructor is accessing
> > memory, we keep MUST_NOT_THROW terminate () call accessible
> > because after inlining the destructor, cleanup might unwind up
> > to that MUST_NOT_THROW.
> > 
> > Questio is how to fix this situation? Shall we link with C++ runtime,
> 
> Please don't.
> 
> > or use -fno-non-call-exceptions
> 
> No, because it might segfault, and we need to catch it.
> 
> > to build this file or somehow restruture
> > code to avoid this case?
> 
> /* Gimplify a MUST_NOT_THROW_EXPR.  */
> 
> static enum gimplify_status
> gimplify_must_not_throw_expr (tree *expr_p, gimple_seq *pre_p)
> {
>   tree stmt = *expr_p;
>   tree temp = voidify_wrapper_expr (stmt, NULL);
>   tree body = TREE_OPERAND (stmt, 0);
>   tree termination;
> 
>   if (pragma_java_exceptions)
>     termination = terminate_node;
>   else
>     termination = abort_node;

OK, pragma_java_exceptions variable is not there, does something like
this work for you?

I would like to commit this to mainline so the MUST_NOT_THROW fix can go
as well.  I am commiting it to pretty-ipa in meantime.

Honza

Index: cp/except.c
===================================================================
*** cp/except.c	(revision 145101)
--- cp/except.c	(working copy)
*************** choose_personality_routine (enum languag
*** 353,358 ****
--- 353,359 ----
  
      case lang_java:
        state = chose_java;
+       terminate_node = built_in_decls [BUILT_IN_ABORT];
        eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
  						 ? "__gcj_personality_sj0"
  						 : "__gcj_personality_v0");

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

* Re: GCC EH unwinding bug and libjava calling std::terminate ()
  2009-03-27 18:28   ` Jan Hubicka
@ 2009-03-27 18:39     ` Andrew Haley
  2009-03-27 18:39       ` Jan Hubicka
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Haley @ 2009-03-27 18:39 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc, java

Jan Hubicka wrote:

> OK, pragma_java_exceptions variable is not there

It's in mainline now.

> does something like this work for you?

Yes.

Andrew.

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

* Re: GCC EH unwinding bug and libjava calling std::terminate ()
  2009-03-27 18:39     ` Andrew Haley
@ 2009-03-27 18:39       ` Jan Hubicka
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Hubicka @ 2009-03-27 18:39 UTC (permalink / raw)
  To: Andrew Haley; +Cc: Jan Hubicka, gcc, java

> Jan Hubicka wrote:
> 
> > OK, pragma_java_exceptions variable is not there
> 
> It's in mainline now.
> 
> > does something like this work for you?
> 
> Yes.

OK, I will do full testing cycle (x86_64-linux) and commit it.
Thanks!
Honza
> 
> Andrew.

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

end of thread, other threads:[~2009-03-27 18:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-27 14:28 GCC EH unwinding bug and libjava calling std::terminate () Jan Hubicka
2009-03-27 18:14 ` Andrew Haley
2009-03-27 18:28   ` Jan Hubicka
2009-03-27 18:39     ` Andrew Haley
2009-03-27 18:39       ` Jan Hubicka

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