|
From: Alex B. <ker...@be...> - 2006-07-10 08:58:29
|
On Sat, 2006-07-08 at 18:14 +1000, Nicholas Nethercote wrote:
> On Sat, 8 Jul 2006, Alex Bennee wrote:
>
> > I've been trying to track down some failures in my program when compiled
> > with -O0 (it's normally compiled -O3 however I like to be able to run
> > -O0 for debugging). I have found problems before with some inlined asm
> > routines before which when not inlined in -O0 don't reserve stack space.
> <snip>
>
> Maybe you can give some more specific detail? I can't tell from your
> description above what it is you want Valgrind to detect.
>
> Nick
Well here is an segment of example of code that failed before I added a
special sub for -O0 builds.
void MyClass::setIfCondition_Zero(uint8_t &condStatus, uint64_t eflags)
{
__asm__ volatile
(
#ifdef OPTIMIZE
#if OPTIMIZE==0
"sub $0x10, %%rsp\n\t"
#endif
#endif
"pushf \n\t"
"push %1 \n\t"
"popf \n\t"
"setz %0 \n\t"
"popf \n\t"
: "=r"(condStatus): "r"(eflags));
}
void MyClass::decodeJumpCC(uint8_t parameter)
{
//lets read our current eflags register
uint64_t intFlags=getEFLAGSValue();
uint8_t doBranch=0;
switch(parameter)
{
// Zero (or not)
case CONDITION_NZ:
inverse=true;
case CONDITION_Z:
setIfCondition_Zero(doSet,intFlags);
break;
...
...
}
In the normal case (-O3) the setIfConditionZero function gets inlined in
the decodeJumpCC code and the pushf/popf gets away with it
because ::decodeJumpCC has a normal stack frame reserved by the compiler
with space for this sort of thing. However in the -O0 case the compiler
won't reserve any space in setIfConditionZero() as it has no local
variables of its own. In this case (after a lot of head scratching) we
fixed it by adding a stack sub to add space for the push/pop operation.
RSP then gets cleaned up by the normal function prolog.
I'm sure there are other cases where we use inline assembler which
doesn't take these sort of stack related things into account. These are
the sort of things it would be useful for Valgrind to detect.
--
Alex, homepage: http://www.bennee.com/~alex/
What I tell you three times is true.
|