I’m writing a C program where I intercept the arguments to a function called by pointer before changing them and forwarding the call to the actual function, and this forwarding is done in assembly. I know that when compiling to x86 it’s possible to mark the calling convention on a per-function basis using attribute((stdcall)) so I need to know two things:
I am open to using other compilers if they support this and gcc does not.
GCC supports two calling conventions on x86-64: the System V ABI conventions used on most Unix-like systems, and the Microsoft x64 convention used on Windows. You can choose a specific one for a function with __attribute__((ms_abi))
or __attribute__((sysv_abi))
. These attributes can also be applied to function pointers. See https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/x86-Function-Attributes.html#x86-Function-Attributes
Try on godbolt. Notice that foo1
and ptr1
have their arguments passed in ecx
and edx
per the MS convention, while foo2
and ptr2
use edi
and esi
as per SysV.
clang behaves the same.
x86-32 (x86)
x86-64 (x64)
See on Wikipedia
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With