Re: Playing with devirtualization in g++4.9

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2 April 2014 17:49, Robert Matusewicz wrote:
>
> I found that g++4.9.0 have -fdevirtualize switch and wanted to play with
> that feature for a while. I wrote simple, non-trivial program to check
> how g++ will behave in obvious case:
>
> ==== SOURCE BEGIN ====
> #include <iostream>
>
> class B final
> {
> public:
>     virtual void test() { std::cout << "Test" << std::endl;  }
> };
>
> int main()
> {
>     B test;
>     test.test();
>     return 0;
> }
> ==== SOURCE ENDS ====
>
> I compiled this code with
>
> g++ -std=c++11 -fdevirtualize simple1.cpp

You can't turn on individual optimisations with just -fxxx switches.

If you don't enable optimisation with -On for n > 0 then no
optimisations happen, so you need at least -O -fdevirtualisation

> and then objdumped symbols:
>
> objdump -t a.out | c++filt  | grep vtable
>
> and noticed that vtable is present (I would expect it will be removed)
> 00000000006012c0  w    O .bss   0000000000000058              vtable for
> __cxxabiv1::__class_type_info@@CXXABI_1.3
> 0000000000400b20  w    O .rodata        0000000000000018              vtable for B

I don't know whether devirtualisation will actually stop the vtable
being emitted into the executable, or whether it just avoids
indirecting through the vtable for the call.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux