The following code breaks when compiled with -O3 or -O2, because the label seems to be misplaced. This problem seems to be restricted to situations where I pass the address of a label into an assembly routine to be used. When compiled without optimizations or with -O1, it works properly. I´m compiling in FreeBSD 5.3-RELEASE gcc version 3.4.3, and I have confirmed that it occurs also on Knoppix 3.6 with compiler version 3.3.4. No flags other than aforementioned optimization flags were used in any case. I hope this is enough info. main() { puts("This line should print.\n"); asm("jmpl *%0\n":: "q" (&&foo)); puts("This line should not print"); foo: puts("And this line should print.\n"); }
This is not a bug, Labels can be moved if you don't use them as computed gotos in which this case you don't use it for that. Also note asms cannot, I repeat cannot change the flow of a program at all.
*** Bug 34634 has been marked as a duplicate of this bug. ***
Note starting with GCC 4.5, gcc adds asm goto which can be used to do what is needed to be done here.