I have an executable file (or a .o
) generated by GCC from C source files. How can I show the calling convention for each function contained within the file, using objdump
or a similar tool?
When looking at the disassembly, I seem to have a function A()
which calls another function B(x, y)
by pushing y
and x
on the stack, but B(x, y)
looks for its parameters in registers.
I don't see any __cdecl
, __stdcall
or similar annotation on the C source code of B(x, y)
, and there don't see any C/C++ incompatibility weirdness, so I'd like to query the convention it's using from the actual .o
or executable file instead of guessing at random.
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.
… interesting, good observation.
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.
This reasoning is wrong. In your case, B
must have been defined as static
; the optimization of loading parameters from registers is not done in functions with external linkage. And this explains why when calling a function in a separate .o
, GCC … generates the right code - it just doesn't perform that optimization then; thus it isn't necessary that GCC knows the convention from some information … contained in the .o
- which isn't there.