gpt4 book ai didi

c - 使用 objdump 或类似工具显示每个函数的调用约定

转载 作者:太空宇宙 更新时间:2023-11-04 03:51:22 25 4
gpt4 key购买 nike

我有一个 GCC 从 C 源文件生成的可执行文件(或 .o)。 如何使用 objdump 显示文件中包含的每个函数的调用约定?或类似的工具?

原因

看反汇编的时候好像有个函数A()调用另一个函数 B(x, y)通过推送 yx在堆栈上,但是 B(x, y)在寄存器中查找其参数。

我没有看到任何 __cdecl , __stdcallB(x, y) 的 C 源代码上的类似注释,并且没有看到任何 C/C++ 不兼容问题,所以我想从实际的 .o 中查询它使用的约定或可执行文件,而不是随机猜测。

最佳答案

A colleague found the problem: somewhere in the (rather long) file there was a #pragma which changed the GCC optimization level (from O2 to O0 I think). So, B was defined with O2 active, and A was defined with O0 active. This shouldn't be a problem, but it seems that GCC version chokes on it, and within A it calls B as if B was O0 too, but O0 and O2 have different calling conventions.

……有趣,很好的观察。

I think that information is contained in the .o, because when calling a function in a separate .o, GCC knows the convention and generates the right code.

这个推理是错误的。在您的情况下,B 必须已定义为 static;从寄存器加载参数的优化没有在具有外部链接的函数中完成。这也解释了为什么 在单独的 .o 中调用函数时,GCC … 生成正确的代码 - 它只是不执行优化;因此,GCC 没有必要从某些 信息中了解约定 ......包含在 .o 中——它不存在。

关于c - 使用 objdump 或类似工具显示每个函数的调用约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20347840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com