users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PPL-devel] Re: Raising Prolog exceptions from C code (2nd attempt)


From: Daniel Diaz
Subject: Re: [PPL-devel] Re: Raising Prolog exceptions from C code (2nd attempt)
Date: Wed, 12 Jun 2002 11:08:59 +0200

Fergus Henderson wrote:
> 
> On 11-Jun-2002, Daniel Diaz <address@hidden> wrote:
> > Fergus is right, GNU Prolog uses ebp to map a WAM register in a physical
> > register (to increase efficiency). Since ebp serves as frame pointer,
> > the code using WAM internals should be compiled with
> > -fomit-frame-pointer. Other code CAN use ebp (since ebp is
> > saved/restored in called functions). But a foreign code needs to be
> > compiled withth -fomit-frame-pointer (and also -O2 or -O3).
> 
> Using `-fomit-frame-pointer' (with or without -O2/-O3) is not sufficient
> to guarantee that the generated code won't use the `ebp' register.
> The `-fomit-frame-pointer' option tells GCC to omit a frame pointer
> where possible, but it's not always possible.  In particular, code
> using variable-length arrays or alloca() always needs a frame pointer.
> There may also be other circumstances in which a frame pointer is required.

True, e.e. recently gcc 3.0.3 used a frame pointer for the main function
(to adjust stack boundary).

> While it's OK to avoid using such features in the code for GNU Prolog
> itself, I don't think it's a good idea to rely on third-party C libraries
> not using ebp when they are compiled with -fomit-frame-pointer.
> That would lead to code which might break when the third-party C library
> is upgraded to the next version.

Not really because if this third-party uses ebp it will then save it at
the entry and restore it at the exit. So the problem comes from foreign
code using a frame pointer (i.e. ebp) and calling a GNU-Prolog library
function expecting ebp contains a valid WAM register.

> 
> I think it would be better for GNU Prolog to save/restore ebp itself,
> either in the code for handling exceptions, or when calling foreign code.
> (However, I'm not that familiar with the internals of GNU Prolog,
> so I don't know how feasible this would be.)
> 
> --
> Fergus Henderson <address@hidden>  |  "I have always known that the pursuit
> The University of Melbourne         |  of excellence is a lethal habit"
> WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
> 
> _______________________________________________
> Users-prolog mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/users-prolog



reply via email to

[Prev in Thread] Current Thread [Next in Thread]