Show each function's calling convention using objdump or similar

888 views Asked by At

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?

Reason

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.

1

There are 1 answers

0
Armali On BEST ANSWER

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.

… 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.