如何从共享库中提取虚拟表信息?

发布于 2024-11-15 17:36:01 字数 452 浏览 3 评论 0原文

我正在实施一个性能分析工具。我正在做的一件事是估计函数调用的成本。为了做到这一点,我需要知道给定的函数在共享库中是否是虚拟的。

为此,我可以访问共享库程序集。我还有一个执行的调用图。我在执行过程中无法做任何事情,必须在执行后使用我从调用图和共享库中获得的信息来完成分析。

我想到的唯一方法是从库中提取vtable并查看我的函数是否在vtable中,但我没有找到从程序集中提取类的vtable的方法。

我尝试过

readelf -s -W lib.so | c++filt | grep vtable

,但这只给了我一个好的虚函数表的地址(至少我认为是一个),而这个地址却无济于事。

共享库是用 gcc 4.3.5 编译的

有人知道获取此 vtable 的方法吗?或者至少有人知道一种方法来知道共享库中的函数是否是虚拟的?

多谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一人独醉 2024-11-22 17:36:01

最后我们找到了一种方法来做到这一点。事情并没有那么复杂。在我们的例子中,虚拟表地址位于 ELF 共享库文件的 .dynsym 部分中。然后虚拟表的内容可在 .rela.dyn 部分中找到。因此,我们必须找到每个虚拟表的地址和大小,然后读取 .rela.dyn 部分来查找函数。

当然,这绝对不是可移植的,但在我们的例子中,这不是问题。

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.

青瓷清茶倾城歌 2024-11-22 17:36:01

0000000000400e80 w O .rodata 0000000000000020 用于测试的 vtable

我使用命令“objdump -x a.out | c++ filt”并获得上面的输出,显然 vtable 正如我们所期望的那样存储在只读部分中。谢谢你的建议。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文