9.3 Calling Conventions and Parameter Passing
A calling convention is an ABI-level contract between caller and callee. If both sides violate it, code may compile and still fail catastrophically at runtime.
The contract defines:
- where arguments are placed (registers and/or stack)
- where return values are produced
- which registers the caller must preserve
- which registers the callee must preserve
- required stack alignment
This is the foundation of cross-module and cross-language interoperability.
Pass by Value vs Pass by Reference
Parameter-passing mode is language semantics plus ABI mechanics.
- pass-by-value copies value semantics into callee context
- pass-by-reference/address allows callee writes to affect caller-visible storage
Compilers must preserve this distinction all the way from semantic analysis to emitted machine-level calling sequence.
Misunderstanding this boundary creates bugs like "callee changed parameter, caller unchanged" when the function signature promised by-value behavior.
Register Pressure and Spill to Stack
Most ABIs assign a fixed number of argument registers. When calls exceed that count, remaining arguments are passed in stack call areas.
This is not an error. It is normal ABI behavior.
From compiler perspective, this affects:
- call-site lowering
- varargs handling
- debug location mapping
- interop correctness with hand-written assembly or foreign-language runtimes
Worked Boundary Case
A function with correct source-level signature may still misbehave if one side assumes SysV x64 register order while another side assumes Win64 order.
This is why ABI knowledge is not optional for backend engineers.