I have a strange problem after turning on level 1 optimization in gcc. What I do is save the label and jmp back to it from a different function later.
void
UMS__suspend_procr( VirtProcr *animatingPr )
{
animatingPr->nextInstrPt = &&ResumePt;
[Some Code and inline volatile asm]
ResumePt:
return;
}
I do some of these jumps and they all work fine.
The problem is that when I turn on O1 it does not save the right label address. Instead it does this:
804b14e: 8b 45 08 mov 0x8(%ebp),%eax
804b151: c7 40 14 4e b1 04 08 movl $0x804b14e,0x14(%eax)
804b158: 8b 55 08 mov 0x8(%ebp),%edx
So the program is jumping back even before the assignment.
This code is not valid GNU C. To begin with, computed gotos (
&&label) are a feature specific to GNU C, not part of the C language, but that’s ok if you’re using GNU C. However, the only place they’re valid in GNU C is with agotostatement. You cannot use the pointer with inline asm as an indirect jump/call destination, because adjusting the stack frame is up to the compiler, and the current logical view of the stack frame from the point of the inline asm and the label destination might not match. With an explicitgotostatement, the compiler can patch this up, but with asm it can’t even tell it’s happening.As for the bigger picture, if you’re writing code like this, you should really rethink some of your assumptions. There’s certainly a better way to accomplish what you want.