Prevent gcc from embedding a function

Is it possible to prevent the gcc compiler from embedding a specific function. If so, how?

Do not tell me to reduce the level of optimization. I want all optimizations to be, but note a specific function, so as not to be an inline compiler, as well as mutable in the case of variables.

And the reason I want to do this is because my function uses the built-in assemblies defined by labels, which gcc confuses when it embeds the function, since inlining calls gcc to create multiple instances of that label.

+6
source share
6 answers

__ attribute __ (noinline) should be placed first, as shown below. Otherwise, the compiler will complain that attributes are not allowed when defining a function.

__attribute__(noinline) void my_function( void * arg ) { ..... } 
+1
source

You must use the noinline attribute

like this:

 void the_method_you_dont_want_to_inline() __attribute__ ((noinline)) { ... } 

or in the latest versions of GCC:

 __attribute__((noinline)) void the_method_you_dont_want_to_inline() { ... } 
+13
source
 void foo() __attribute__ ((noinline)) { } 
+2
source

You must set the __attribute__((noinline)) argument to the function.

It will look something like this:

 void __attribute__((noinline)) MyFunction(void) { printf("This will never be inlined"); } 
+2
source

__attribute__(noinline) is the closure you are about to receive.

+2
source

Another way is to give an attribute of the declaration, not a function definition; eg.

 static void foo() __attribute__ ((noinline)); 

and later

 static void foo() { //code here } 

But maybe you can still __label__ function using local labels with __label__ inside it, something like

 static void inline foo() { // untested! __label__ foo; foo: asm ("do something tricky"); goto foo; } 

But MetallicPriest, you should give more details and perhaps show more of your code and goals in order to get better help!

+1
source

Source: https://habr.com/ru/post/900603/


All Articles