Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing gcc from inlining a function [duplicate]

Tags:

c

linux

x86

gcc

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

Don't tell me to reduce the optimization level. I want all optimizations on, but mark a particular function to no be inlined by the compiler, just like volatile in case of variables.

And the reason I want to do this is because my function uses inline assembly defined labels, which gcc messes up when it inlines the function, as inlining causes gcc to create multiple instances of that label.

like image 657
MetallicPriest Avatar asked Nov 02 '11 11:11

MetallicPriest


1 Answers

You should use the noinline attribute

like this :

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

or in recent versions of GCC :

__attribute__((noinline)) void the_method_you_dont_want_to_inline()
{
  ...
}
like image 89
Cédric Julien Avatar answered Oct 03 '22 03:10

Cédric Julien