From mboxrd@z Thu Jan 1 00:00:00 1970 Message-Id: <200207191253.NAA06845@cthulhu.dircon.co.uk> Subject: Re: [9fans] useful language extension, or no? In-Reply-To: <06b78404a549aa66986788bcb976b339@plan9.bell-labs.com> from David Gordon Hogan at "Jul 18, 2002 08:52:21 pm" To: 9fans@cse.psu.edu From: Digby Tarvin MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Date: Fri, 19 Jul 2002 13:53:30 +0100 Topicbox-Message-UUID: d203870c-eaca-11e9-9e20-41e7f4b1d025 > Interesting. My guess is that it's creating a > trampoline on the stack, which calls the real > g(), which nm tells me is at: > > 080485a6 t g.0 > Unfortunately gdb on the Linux server is unable to show > me the instructions: > Why not just get the compiler to generate the assembly language for you. It is interesting that the current compiler lets you do it (my old BSD system won't swallow it) but I can't see any attempt to actually execute any code on the stack. For instance, adding code to actually call the function: int bar(){ int i; int g(){;} int h; printf("foo=%x\n",foo); printf("bar=%x\n",bar); printf("i=%x\n",&i); printf("g=%x\n",g); printf("h=%x\n",&h); g(); } generates . . call printf addl $16,%esp movl %ebp,%ecx call g.6 .L3: movl %ebp,%esp popl %ebp ret where g.6 is in the code segment: g.6: pushl %ebp movl %esp,%ebp subl $24,%esp movl %ecx,-4(%ebp) .L4: movl %ebp,%esp popl %ebp ret and the address of the function is put on the stack, but not used in the call: bar: pushl %ebp movl %esp,%ebp subl $56,%esp leal -36(%ebp),%edx leal 15(%edx),%eax andb $240,%al movl $g.6,%edx leal 10(%eax),%ecx subl %ecx,%edx movb $185,(%eax) movl %ebp,1(%eax) movb $233,5(%eax) movl %edx,6(%eax) addl $-8,%esp pushl $foo pushl $.LC0 call printf . . This is assuming I am reading the Intel code correctly. I am much more at home with Motorola or DEC assembly language, but I think these code fragments seem pretty clear. I don't really understand the need to have a pointer to the function on the stack, but I am sure there is a good reason for it. Thre restricted scope of the function name, which I guess could be useful, does not seem to depend on it. Regards, DigbyT -- Digby R. S. Tarvin digbyt@acm.org http://www.cthulhu.dircon.co.uk