How to extract Virtual Table informations from a shared library?

亡梦爱人 提交于 2019-12-22 13:07:21

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6379166/how-to-extract-virtual-table-informations-from-a-shared-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!