我有一个 GCC 从 C 源文件生成的可执行文件(或 .o
)。 如何使用 objdump
显示文件中包含的每个函数的调用约定?或类似的工具?
原因
看反汇编的时候好像有个函数A()
调用另一个函数 B(x, y)
通过推送 y
和 x
在堆栈上,但是 B(x, y)
在寄存器中查找其参数。
我没有看到任何 __cdecl
, __stdcall
或 B(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 (fromO2
toO0
I think). So,B
was defined withO2
active, andA
was defined withO0
active. This shouldn't be a problem, but it seems that GCC version chokes on it, and withinA
it callsB
as ifB
wasO0
too, butO0
andO2
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/