bad dead code detection ?
David Jobet
david.jobet@free.fr
Wed Jun 25 16:49:00 GMT 2003
Hello,
I try to write an exception handling library, and I'm forced to play with gcc
inline assembly.
You will find below a sample program.
The trick is to register address of local labels in a global static table. Later
when an exception is launched, I manage to jump to this label to do clean up.
The problem is gcc detects the label cannot be reached and dead code elimination
completely remove the exception handling code from the executable when compiled
with -O3.
When compiled without -03, the code is not removed, but the label is moved from
the *good* location to the return label.
I'm wondering if it's a bug, or if there is a way to prevent this.
When one take the address of a local variable, it cannot be put in a register.
I'm wondering if it should not be the same with code taking address of local
labels ?
Kind regards
David
---
void g(int throwError)
{
// STATIC DATA **************************************************************
// strings
// --snip--
static unsigned int initialised = 0;
// nosica variables *********************************************************
// --snip--
void *jumpToLabel;
// static initialisation
if (!initialised)
{
___cleanUpPoints[1] = &&g_cleanUpPoint; // registering in static table
initialised = 1;
}
// nosica code **************************************************************
// --snip--
return_label : // without -O3, the assembly code shows g_cleanUpPoint to be the
same as return_label
return;
g_cleanUpPoint :
// --snip--
___currentReturnAddress(pc); // get 4(%%ebp)
jumpToLabel = ___nextCleanUpPointByReturnAddress(pc);
___nonLocalGoto(jumpToLabel);// similar to a setjmp
}
Nothing happens unless first a dream (Carl Sandburg)
More information about the Gcc
mailing list