Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling convention on x64 [duplicate]

I saw in several places that Microsoft calling conventions for x64 platforms were narrowed down to just one: Caller cleans stack (cdecl), and parameters are passed in a combination of stack and registers (I am not going into the exact details here). I assume that if this is the calling convention of the OS, then probably all other compilers targeting Windows (e.g. mingw-w64) follow it, too.

Is this calling convention true also on other major platforms (x64 Linux, etc.)? Or does Linux still use multiple calling conventions, or even just one but a different one? Do GCC or Clang allow for multiple calling conventions on x64 Linux?

like image 473
Baruch Avatar asked Aug 08 '13 20:08

Baruch


People also ask

What does __ Stdcall mean?

__stdcall is a calling convention: a way of determining how parameters are passed to a function (on the stack or in registers) and who is responsible for cleaning up after the function returns (the caller or the callee).

What is the name of the calling convention for 64 bit Windows executables?

Calling convention defaults The x64 Application Binary Interface (ABI) uses a four-register fast-call calling convention by default. Space is allocated on the call stack as a shadow store for callees to save those registers.

What is the difference between Stdcall and cdecl?

In CDECL arguments are pushed onto the stack in revers order, the caller clears the stack and result is returned via processor registry (later I will call it "register A"). In STDCALL there is one difference, the caller doeasn't clear the stack, the calle do. You are asking which one is faster.

What is __ cdecl in C++?

The __cdecl function specifier (C++ only) The __cdecl keyword instructs the compiler to read and write a parameter list by using C linkage conventions. To set the __cdecl calling convention for a function, place the linkage keyword immediately before the function name or at the beginning of the declarator.


1 Answers

I just found the answer here and here. Basically, Windows does it one way, everyone else does it another way, but each platform only does it one way (as opposed to multiple ways per-platform with x86)

like image 100
Baruch Avatar answered Oct 06 '22 03:10

Baruch