Search code examples
cgccstackparameter-passingcalling-convention

Force gcc to pass the parameters on the stack


Is there a way to force gcc to pass the parameters of a function on the stack?

I don't want to use the registers for parameter passing.

Update: I'am using arm-gcc from CodeSourcery


Solution

  • According to: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf

    The first four registers r0-r3 (a1-a4) are used to pass argument values into a subroutine and to return a result value from a function. They may also be used to hold intermediate values within a routine (but, in general, only between subroutine calls).

    There are, on ARM, no other calling conventions but the default, that I know of. And here is why:

    1. Why would you want to? Your function would not be callable in compiled form by other functions, creating a compatibility mess.
    2. Your calls to system functions which comply with the ABI wouldn't work, unless the compiler was able to differentiate between calling conventions. Now, I know in the past there are different calling conventions for x86-32, but notice how x64 is simpler (AMD64 vs whatever Microsoft did). Why, when designing the ARM calling convention, would you allow so many different calling conventions? It creates a compatibility mess.