dotgnu-libjit
[Top][All Lists]
Advanced

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

Re: [Libjit-developers] how do the nested functions work?


From: kmeaw
Subject: Re: [Libjit-developers] how do the nested functions work?
Date: Sun, 17 Jun 2007 23:57:41 +0400
User-agent: Thunderbird 2.0.0.4 (X11/20070616)

address@hidden пишет:
> Hi,
> 
> i haven't used thm by now but i'm thinking to use them for cleanup functions.
> 
> My guess on the implementation is that for nested functions there is no new 
> stackframe.
> On x86 that means that %ebp is still the same as for the paremt function and 
> the locals are accessed %ebp relative.
> So only the return address is pushed onto the stack.

It would fail, if one adds another nesting level:

void main()
{
  int x = 3;
  void f1()
  {
    int y = 4;
    void f2()
    {
      printf ("%d %d\n", x, y);
    }
    void f3()
    {
      f2();
    }
    f2();
    f3();
  }
  void f4()
  {
    f1();
  }
  f1(); /* (1) */
  f4(); /* (2) */
}

f2 has no information about the "distance" of x and y in the stack,
which differs on calls (1) and (2). In the case of (1), the distance is
2 (return address of f1 and y itself). In the case of (2), the distance
is 3 (return address of f4, return address of f1 and y itself). If %ebp
points to main's stack, then the will have the ability to track that
distance, but similar problem will occur to y.

Currently, my compiler keeps track of stack length on each function
call. Local stack variables and function arguments are referenced as
(0xXX)%esp, parent variables as (0xXX)%ebp. The compiler does lea
0xXX(%esp), %ebp, where XX is the difference in stack length of caller
and callee. It fails on the above example.

> Cheers,
> 
> Klaus

--
kmeaw


reply via email to

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