I read somewhere that for an cdecl call the registers eax, ecx and edx do not need to be preserved by the called function. However, when testing the following code on gcc:
Code: Select all
#include <stdio.h>
void __attribute__((cdecl)) test()
{
__asm__("movl $0, %eax");
}
int __attribute__((cdecl)) test1()
{
int a;
scanf("%d", &a);
return a;
}
int main()
{
int a = test1();
test();
printf("%d\n", a);
}
What about the other registers? They are not preserved, is that correct?
What about the syscall calling convention? Is the same true, there?
Also, how do I specify the calling convention to use in gcc? The above actually complains about it being ignored - but I believe cdecl is the default in gcc anyway (otherwise my complaint is even wrong). So how would I specify the syscall calling convention, for instance?
Edit: never mind this last question, I was accidentally compiling it on 64 bits, which is why cdecl was ignored. But the issue with eax was not fixed compiling it as 32 bits.
Thanks in advance