Preventing link time optimization from inlining

Richard Günther
Fri Dec 21 16:10:00 GMT 2012

Adam Lewis <> wrote:

>On Fri, Dec 21, 2012 at 4:41 AM, Richard Biener
>> On Thu, Dec 20, 2012 at 5:33 PM, Adam <> wrote:
>> > Hi,
>> >
>> > When using -flto is there a way to tell gcc to not inline a
>> function? attribute noinline appears to have no effect. I am using
>> 4.7.2. The use case is for certain functions that cause optimization
>> problems when they are inlined. An example is when the function is
>> a c++ exception.
>> attribute noinline should have the desired effect (you may need
>> noclone as well).
>> Richard.
>Doesn't seem to work for me. Here is what I am trying:
>func.hpp ( I have tried this with various combinations and orderings of
>noinline, noclone ):
>void  my__func() __attribute__((noinline)) __attribute__ ((noclone));
>#include <cstdio>
>void my__func() { printf("prnting"); }

The attribute is missing here. Or the include.

>#include "func.hpp"
>int main() { my__func(); return 0; }
>g++ -O3 -g -flto main.cpp func.cpp -o lto_inline_test
>I load up gdb, break main, run. disassemble and see that it is directly
>calling printf instead of my__func.
>gcc -v:
>Using built-in specs.
>Target: x86_64-linux-gnu
>Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
>--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
>--program-suffix=-4.7 --enable-shared --enable-linker-build-id
>--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
>--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7
>--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
>--enable-libstdcxx-debug --enable-libstdcxx-time=yes
>--enable-gnu-unique-object --enable-plugin --enable-objc-gc
>--disable-werror --with-arch-32=i686 --with-abi=m64
>--with-multilib-list=m32,m64 --with-tune=generic
>--build=x86_64-linux-gnu --host=x86_64-linux-gnu
>Thread model: posix
>gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-11precise2)
>Any thoughts?
>> > Thanks,
>> > Adam

Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

More information about the Gcc mailing list