From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: To: 9fans@cse.psu.edu Subject: Re: [9fans] useful language extension, or no? From: forsyth@vitanuova.com MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Fri, 19 Jul 2002 16:45:14 +0100 Topicbox-Message-UUID: d2293f60-eaca-11e9-9e20-41e7f4b1d025 it only uses the trampoline code when you call g indirectly through a function pointer. if you call it directly it can provide the static link itself without that fuss. when you create a function pointer to g, as in the call to printf, it does generate code onto the stack that loads the static link register then enters g. leal -16(%ebp),%eax movl $g.9-10,%edx movb $185,(%eax) movl %ebp,1(%eax) movb $233,5(%eax) subl %eax,%edx movl %edx,6(%eax) that's the generation on the fly of the trampoline code. note the movl %ebp,1(%eax), which stores the current frame pointer as a literal in the generated code. the `function pointer' that is later passed to printf is the address of -16(%ebp) [offsets might be different in your case], which when called will load the literal, and enter g with a pc-relative reference (i think that's about right). you'd need to flush the cache(s) on some architectures, which is tricky when it's a privileged operation. the problem it is trying to solve is to get the right value for the static link register, without passing the required value along with the function pointer as a pair. providing the right value for the static link register is easiest to do if it doesn't exist. there are several approaches to implementing displays, and one of them allows nested function pointers as a single word but without this crud. all these implementations of nested functions in C go sadly wrong if you call a nested function indirectly when it has gone out of scope.