|
From: Josef W. <Jos...@gm...> - 2003-11-19 15:26:24
|
Hi,
just looked at this strange piece of code.
Now I know why Intel refuses to support nested functions in their
compilers ;-)
When GCC-compiled code needs a function pointer for a nested function, it
seems to produce dynamically some trampoline code on the stack, and uses the
start address of this piece of code as the function pointer (don't ask me
why).
Note that the function pointer for the nested function will point to the same
address of dynamically produced code. Valgrind's instrumentation engine
doesn't detect that the code on stack is changed inbetween, and uses
the same instrumented version both times.
The code works as expected if you change call_func() this way:
=============================================
#include <valgrind/valgrind.h>
...
static void call_func(void (*sel)(void))
{
sel();
VALGRIND_DISCARD_TRANSLATIONS(sel,20);
}
=============================================
Note that VG would be quite slow if it had to check if a write instruction
is about to change already instrumented code (Wasn't this the
case in the first days of VG?).
Josef
|