|
From: Duncan S. <bal...@fr...> - 2005-05-03 07:22:48
|
> > I guess my pointer to the local function is actually a pointer to the
> > trampoline code, so I guess I can use that as the start address. Any
> > idea how much code a trampoline can contain? Does it actually vary
> > depending on the number of local variables used as function arguments?
>
> No idea, but I'd hope it's small, eg. only a handful of instructions.
> The good thing is that you can be conservative -- all that will happen is
> that Valgrind will flush any translations it is holding for that range of
> addresses, which could possibly slow it down. Try 100 bytes, or 1000, see
> if that helps.
>From gcc/config/i386/i386.h:
/* On the 386, the trampoline contains two instructions:
mov #STATIC,ecx
jmp FUNCTION
The trampoline is generated entirely at runtime. The operand of JMP
is the address of FUNCTION relative to the instruction following the
JMP (which is 5 bytes long). */
/* Length in units of the trampoline for entering a nested function. */
#define TRAMPOLINE_SIZE (TARGET_64BIT ? 23 : 10)
> > I said that wrong: my program explodes, valgrind produces a ton of error
> > messages, and everything exits. valgrind is not crashing in any way as
> > far as I can see. I guess the problem is that in the routine in
> > question there are two code paths each of which leads to the address
> > being taken of a (different) local procedure - presumably this is
> > why there are sometimes different trampolines at the same stack address.
> > It is to be expected that the program dies if the wrong one is called...
>
> Right. Unfortunately you've hit a dark corner of Valgrind that doesn't
> work very well. As the commentary on bug #69511 suggests, we don't have a
> good solution for this problem, since detecting it would be very
> expensive.
By the way, local procedures are much more widely used in a language
like Ada, than in C. As a data point, I ran all the ACATS tests (see
the gcc testsuite/ada directory) under valgrind, and the majority of
failures were spurious, coming from the trampoline problem. On the
other hand, there are about 1800 tests, and only about 50 triggered
the trampoline problem (I don't recall the exact number), so it's not
that common either.
All the best,
Duncan.
|