> > 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. This definition method is not granular enough. I don't want the entire function in the 'bar' section. I want the entire function in the 'text' section but in some cases in the function where there is an if-statement like this: if (something) { /* body /* } ...I want to place the body, which is written in C, in the 'bar' section. And everything after the if-statement should remain in the 'text' section. I'm currently producing if (something) { relocate_pre("if_something"); /* body */ relocate_post(); } And then defining: #define relocate_pre(name) \ asm volatile ( "jmp 1f\n\t" \ ".subsection 2\n\t" \ ".section .bar\n" \ "hcu_uncommon_section_" name ":\n\t" \ "1:\n\t" ); #define relocate_post() \ asm volatile( "jmp 1f\n\t" \ ".text\n\t" \ "1:\n" ); The problems begin when I hit a case like: if (something) { relocate_pre("if_something"); /* parts of the body */ goto somewhere_else; relocate_post(); } or if (something) { relocate_pre("if_something"); /* parts of the body */ return; relocate_post(); } relocate_post() seems to be eliminated, hence I don't get the switch back to the ".text" section. > > If you really need naked assembly code, do it *outside* a function: > > asm ("\nfoo:\t\n" > "\t# wibble"); > > int main(void) > { > return 0; > } The problem with using naked assembly code outside a function is that after such code I may need to execute additional code written in C, and presently there's no way to write such code in C outside a function. I requested a feature like this in the past, but it was not accepted: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12118 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12284 I'm applying an automated transformation to 3rd-party source code to produce such uncommon code in separate memory regions. Certainly, interpreting the body of if-statements as C code and automatically producing the corresponding naked assembly outside a function image seems like something the compiler or assembler should be doing. It shouldn't be hand written. I can't help but feel that the compiler should be helping here.