From my knowledge, the calling convention is depending on whether the platform is Windows or Linux.
I wanna know,
- Compilers make the calling convention different.
- Platforms make the calling convention different.
Which one is true? if only 2 is true, is the calling convention is defined by the platforms, and do the compilers just follow the defined convention?
CodePudding user response:
Platforms generally define one or more "standard" calling conventions. Compilers need to follow those conventions if they want to interoperate with other tools or components on the platform using those conventions, but can use their own different calling conventions internally.
The only real requirement is that any caller and callee need to agree on the conventions for the call between them.
CodePudding user response:
Related: Why does Windows64 use a different calling convention from all other OSes on x86-64? talks about who defined the calling convention.
In that case, GCC developers effectively decided on behalf of the whole platform for the x86-64 System V ABI.
Obviously compiler devs are the most likely people to be able to design a good one, but once it's set, other people making new compilers have to follow it if they want to be compatible.
All non-Windows OSes chose to follow the same x86-64 System V calling convention because it was pretty well designed, so the set of platforms it covers grew to include all non-Windows OSes. Partly because they all use GCC and GCC-compatible compilers. It's not like developers of different compilers got together to agree on a calling convention they'd all follow for that platform, there was only one major free non-Windows C compiler at that time (early 2000s).