I'm implementing a开发者_开发百科 performance analysis tool. One thing that I'm doing is to estimate the cost of a function call. In order to do that, I need to know if a given function is virtual in a shared library.
For that, I have access to the shared library assembly. I have also a call graph of the execution. I cannot make anything during the execution, the analysis has to be done after the execution using the information I can obtain from the call graph and the shared libraries.
The only way I've thought of is to extract the vtable from the library and look if my function is in the vtable, but I didn't find a way to extract the vtable of a class from the assembly.
I tried
readelf -s -W lib.so | c++filt | grep vtable
but that only give me an address of the good vtable (at least I think it's one) and this address lead me nowhere.
The shared library is compiled with gcc 4.3.5
Does someone know a way to obtain this vtable ? Or at least does someone know a way to know if a function is virtual in a shared library ?
Thanks a lot
Finally we found a way to do that. It was not so complicated. In our case, the virtual tables addresses are in the .dynsym section of the ELF shared library file. And then the content of the virtual table is available on the .rela.dyn section. So we have to find the address and the size of every virtual table and then just read the .rela.dyn section to find the functions.
Of course, this is absolutely not portable, but in our case, this is not a problem.
0000000000400e80 w O .rodata 0000000000000020 vtable for Test
i use the command "objdump -x a.out | c++ filt" and get the output above, obviously the vtable stored in the read only section as our expect. thank you for your advice.
精彩评论