Forcing inline assembly code to be produced
Andrew Haley
aph-gcc@littlepinkcloud.COM
Mon Apr 23 18:38:00 GMT 2007
Kristis Makris writes:
> Hello,
>
> I'm facing a problem producing inline assembly code in a C program. It
> seems that when assembly code is added in a path that seems to be
> unreachable (dead-code I suppose) the assembly code is not produced at
> all.
Right.
> I'm using gcc 3.3.5 and as 2.15.
> Is there a way to force such assembly code to be produced even though it
> may be unreachable ? If not should there be a way ?
If code is unreachable, there's no way to jump to it. It's not legal
in gcc to jump into or out of an inline asm.
> I'm attaching a simplified test case I'm using. I'm trying to generate a
> symbol with inline assembly.
>
> In a more complicated example, I'm trying to position uncommonly used
> code in a separate memory region for better cache locality. One of the
> inline assembly statements I'm using is not produced. This results in
> not changing back to the ".text" section, resulting in further assembler
> problems as described in:
Use an attribute to set the section.
extern void foobar (void) __attribute__ ((section ("bar")));
puts the function `foobar' in the `bar' section.
> http://lists.gnu.org/archive/html/bug-binutils/2007-04/msg00107.html
>
> Thanks for any help.
> Kristis
> #include <stdio.h>
>
>
> int main(void)
> {
> int a = 7;
>
> goto there;
>
> here:
> exit(0);
>
> there:
> a++;
> goto here;
>
> asm ("some_label_that_i_really_want_produced:\n\t"
> "nop\n\t"
> "nop\n\t"
> "nop\n\t"
> "nop\n\t" );
> }
There's no way to guarantee that the asm will remain at the end of the
function. gcc could convert this to:
int main(void)
{
int a = 7;
a++;
goto here;
asm ("some_label_that_i_really_want_produced:\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t" );
here:
exit(0);
}
If you really need naked assembly code, do it *outside* a function:
asm ("\nfoo:\t\n"
"\t# wibble");
int main(void)
{
return 0;
}
Andrew.
More information about the Gcc-help
mailing list