public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Using EH from C
@ 2004-05-02  4:39 david daney
  2004-05-02  9:17 ` Stelios Xanthakis
  0 siblings, 1 reply; 13+ messages in thread
From: david daney @ 2004-05-02  4:39 UTC (permalink / raw)
  To: Stelios Xanthakis, Richard Henderson; +Cc: gcc

On Sat, 1 May 2004, Richard Henderson wrote:

>> On Sat, May 01, 2004 at 05:09:23PM +0300, Stelios Xanthakis wrote:
>> > But of little use without another extension to create landing pads...:(
>>
>> Why in the world would you need that?

>Because if there's no landing pad, _Unwind_RaiseException
>ends up on abort()?
>
>I may be totally wrong, but what I'm trying to do is implement
>"stack unwind with cost-free cleanups from C".
>
>That's three things
>
>1. register destructors on EH
>  Done: attribute(cleanup(function))
>
>2. call 'throw'
>  Done: libgcc_eh and unwind.h
>
>3. set up a landing pad somewhere (try-catch).
>  ???
>
>Where does _Unwind stop otherwise? main()?
>
>~S


gcc/testsuite/gcc.dg/cleanup9.c kind of does what you are talking about.  I would setjump and set an attfibute(cleanup(function)) at the catch point, and then longjump from the cleanup function.
 
Why can't you use C++ for the try/catch part?  Since all of this is GCC specific, if you have C and excpetions working it doesn't seem like using G++ would be a problem.
 
David Daney.
 

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

* RE: Using EH from C
  2004-05-02  4:39 Using EH from C david daney
@ 2004-05-02  9:17 ` Stelios Xanthakis
  2004-05-03 11:18   ` Stelios Xanthakis
  0 siblings, 1 reply; 13+ messages in thread
From: Stelios Xanthakis @ 2004-05-02  9:17 UTC (permalink / raw)
  To: david daney; +Cc: Richard Henderson, gcc



On Sat, 1 May 2004, david daney wrote:

> 
> I would setjump and set an attfibute(cleanup(function))
> at the catch point, and then longjump from the cleanup function.
>  

Not a bad idea. Like this?

	if (setjmp (&context)) {
		struct pseudo_object X __attribute__((cleanup(pdtor)));
		X.normal_termination = 0;
		X.ctx = &context;
		/* ... */
		X.normal_termination = 1;
	} else {
	}

And pdtor() will either just return or longjmp to ctx depending
on normal_termination.

There's still a minor cost but I guess it's ok.

Thanks,

Stelios


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

* RE: Using EH from C
  2004-05-02  9:17 ` Stelios Xanthakis
@ 2004-05-03 11:18   ` Stelios Xanthakis
  2004-05-03 16:32     ` Richard Henderson
  0 siblings, 1 reply; 13+ messages in thread
From: Stelios Xanthakis @ 2004-05-03 11:18 UTC (permalink / raw)
  To: david daney; +Cc: Richard Henderson, gcc



On Sun, 2 May 2004, Stelios Xanthakis wrote:

> On Sat, 1 May 2004, david daney wrote:
> 
> > 
> > I would setjump and set an attfibute(cleanup(function))
> > at the catch point, and then longjump from the cleanup function.
> >  
[snip] 
> And pdtor() will either just return or longjmp to ctx depending
> on normal_termination.
> 

Although the manual sais:
``  Note that the `cleanup' attribute does not allow
      the exception to be caught, only to perform an action.  It is
      undefined what happens if CLEANUP_FUNCTION does not return
      normally. ''

Seems like somebody already thought that somebody else might
think of using 'cleanup' to catch exceptions :)

For the moment it works and I hope we can resolve this in the
next version. If the only problem is the un-freed struct
_Unwind_Exception, we can take care of it.


stelios



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

* Re: Using EH from C
  2004-05-03 11:18   ` Stelios Xanthakis
@ 2004-05-03 16:32     ` Richard Henderson
  0 siblings, 0 replies; 13+ messages in thread
From: Richard Henderson @ 2004-05-03 16:32 UTC (permalink / raw)
  To: Stelios Xanthakis; +Cc: david daney, gcc

On Mon, May 03, 2004 at 02:17:56PM +0300, Stelios Xanthakis wrote:
> Seems like somebody already thought that somebody else might
> think of using 'cleanup' to catch exceptions :)

See glibc's pthread unwind implementation.  The correct place to 
put the longjmp is in the force unwind handler.


r~

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

* Re: Using EH from C
  2004-05-01 18:13       ` Richard Henderson
@ 2004-05-02  2:12         ` Stelios Xanthakis
  0 siblings, 0 replies; 13+ messages in thread
From: Stelios Xanthakis @ 2004-05-02  2:12 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc



On Sat, 1 May 2004, Richard Henderson wrote:

> On Sat, May 01, 2004 at 05:09:23PM +0300, Stelios Xanthakis wrote:
> > But of little use without another extension to create landing pads...:(
> 
> Why in the world would you need that?

Because if there's no landing pad, _Unwind_RaiseException
ends up on abort()?

I may be totally wrong, but what I'm trying to do is implement
"stack unwind with cost-free cleanups from C".

That's three things

1. register destructors on EH
  Done: attribute(cleanup(function))

2. call 'throw'
  Done: libgcc_eh and unwind.h

3. set up a landing pad somewhere (try-catch).
  ???

Where does _Unwind stop otherwise? main()?

~S

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

* Re: Using EH from C
  2004-05-01 14:09     ` Stelios Xanthakis
@ 2004-05-01 18:13       ` Richard Henderson
  2004-05-02  2:12         ` Stelios Xanthakis
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Henderson @ 2004-05-01 18:13 UTC (permalink / raw)
  To: Stelios Xanthakis; +Cc: gcc

On Sat, May 01, 2004 at 05:09:23PM +0300, Stelios Xanthakis wrote:
> But of little use without another extension to create landing pads...:(

Why in the world would you need that?


r~

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

* Re: Using EH from C
  2004-04-30 16:10   ` Stelios Xanthakis
@ 2004-05-01 14:09     ` Stelios Xanthakis
  2004-05-01 18:13       ` Richard Henderson
  0 siblings, 1 reply; 13+ messages in thread
From: Stelios Xanthakis @ 2004-05-01 14:09 UTC (permalink / raw)
  To: gcc



On Fri, 30 Apr 2004, Stelios Xanthakis wrote:

> 
> On Thu, 29 Apr 2004, Richard Henderson wrote:
> 
> > On Thu, Apr 29, 2004 at 02:07:18PM +0300, Stelios Xanthakis wrote:
> > > The main challenge is 'calling destructors on unwind
> > > with no performance cost if  no exception is raised'.
> > 
> >   type var __attribute__((cleanup(function)));
> 
> That's just great.

But of little use without another extension to create landing pads...:(

Or is there?



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

* Re: Using EH from C
  2004-04-29 22:46 ` Richard Henderson
  2004-04-30  2:35   ` Giovanni Bajo
@ 2004-04-30 16:10   ` Stelios Xanthakis
  2004-05-01 14:09     ` Stelios Xanthakis
  1 sibling, 1 reply; 13+ messages in thread
From: Stelios Xanthakis @ 2004-04-30 16:10 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc



On Thu, 29 Apr 2004, Richard Henderson wrote:

> On Thu, Apr 29, 2004 at 02:07:18PM +0300, Stelios Xanthakis wrote:
> > The main challenge is 'calling destructors on unwind
> > with no performance cost if  no exception is raised'.
> 
>   type var __attribute__((cleanup(function)));

That's just great.

Thanks.

Stelios

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

* Re: Using EH from C
  2004-04-30  3:15     ` Richard Henderson
@ 2004-04-30  3:36       ` Mike Stump
  0 siblings, 0 replies; 13+ messages in thread
From: Mike Stump @ 2004-04-30  3:36 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Giovanni Bajo, Stelios Xanthakis, gcc

On Thursday, April 29, 2004, at 06:48 PM, Richard Henderson wrote:
> On Fri, Apr 30, 2004 at 02:36:24AM +0200, Giovanni Bajo wrote:
>>>   type var __attribute__((cleanup(function)));
>>
>> It looks like this was never applied though:
>
> That would be incorrect.  Glibc uses it today.

The link was to some doc content.  Lack of that doesn't prevent glibc 
from using it.

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

* Re: Using EH from C
  2004-04-30  2:35   ` Giovanni Bajo
@ 2004-04-30  3:15     ` Richard Henderson
  2004-04-30  3:36       ` Mike Stump
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Henderson @ 2004-04-30  3:15 UTC (permalink / raw)
  To: Giovanni Bajo; +Cc: Stelios Xanthakis, gcc

On Fri, Apr 30, 2004 at 02:36:24AM +0200, Giovanni Bajo wrote:
> >   type var __attribute__((cleanup(function)));
> 
> It looks like this was never applied though:

That would be incorrect.  Glibc uses it today.


r~

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

* Re: Using EH from C
  2004-04-29 22:46 ` Richard Henderson
@ 2004-04-30  2:35   ` Giovanni Bajo
  2004-04-30  3:15     ` Richard Henderson
  2004-04-30 16:10   ` Stelios Xanthakis
  1 sibling, 1 reply; 13+ messages in thread
From: Giovanni Bajo @ 2004-04-30  2:35 UTC (permalink / raw)
  To: Richard Henderson, Stelios Xanthakis; +Cc: gcc

Richard Henderson wrote:

>> The main challenge is 'calling destructors on unwind
>> with no performance cost if  no exception is raised'.
> 
>   type var __attribute__((cleanup(function)));

It looks like this was never applied though:
http://gcc.gnu.org/ml/gcc-patches/2003-06/msg00658.html

Giovanni Bajo


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

* Re: Using EH from C
  2004-04-29 12:51 Stelios Xanthakis
@ 2004-04-29 22:46 ` Richard Henderson
  2004-04-30  2:35   ` Giovanni Bajo
  2004-04-30 16:10   ` Stelios Xanthakis
  0 siblings, 2 replies; 13+ messages in thread
From: Richard Henderson @ 2004-04-29 22:46 UTC (permalink / raw)
  To: Stelios Xanthakis; +Cc: gcc

On Thu, Apr 29, 2004 at 02:07:18PM +0300, Stelios Xanthakis wrote:
> The main challenge is 'calling destructors on unwind
> with no performance cost if  no exception is raised'.

  type var __attribute__((cleanup(function)));


r~

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

* Using EH from C
@ 2004-04-29 12:51 Stelios Xanthakis
  2004-04-29 22:46 ` Richard Henderson
  0 siblings, 1 reply; 13+ messages in thread
From: Stelios Xanthakis @ 2004-04-29 12:51 UTC (permalink / raw)
  To: gcc


Hi.

I'm working on a 'C++ to C' code generator and I'm trying
to figure out (how|if) it's possible to use unwind info from
C programs. The main challenge is 'calling destructors on unwind
with no performance cost if  no exception is raised'. This probably
means that we will have to construct unwind tables manually
by getting the addresses of labels and putting them in  special
sections. And the -funwind-tables?

If anybody knows, please contact me.

Thanks and sorry for the OT but this seems
to be a quiet period on the list, I couldn't find any
info on google and Aldy said I should ask here.

stelios


- The project is [http://students.ceid.upatras.gr/~sxanth/lwc]

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

end of thread, other threads:[~2004-05-03 16:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-02  4:39 Using EH from C david daney
2004-05-02  9:17 ` Stelios Xanthakis
2004-05-03 11:18   ` Stelios Xanthakis
2004-05-03 16:32     ` Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
2004-04-29 12:51 Stelios Xanthakis
2004-04-29 22:46 ` Richard Henderson
2004-04-30  2:35   ` Giovanni Bajo
2004-04-30  3:15     ` Richard Henderson
2004-04-30  3:36       ` Mike Stump
2004-04-30 16:10   ` Stelios Xanthakis
2004-05-01 14:09     ` Stelios Xanthakis
2004-05-01 18:13       ` Richard Henderson
2004-05-02  2:12         ` Stelios Xanthakis

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