What is the size of excessive parameters passed via stack?
C code:
int f(int a, int b, int c, int d, int e, int f, int g, int h, int i) {f = 8; g = 3; h=9; i = 12; return g;}
int main() {
f(1,2,3,4,5,6,7,8,9);
return 0;
}
is compiled with gcc -S -masm=intel sth.c to:
.file "passord.c"
.intel_syntax noprefix
.text
.globl f
.type f, @function
f:
.LFB0:
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mov rbp, rsp
.cfi_def_cfa_register 6
mov DWORD PTR -4[rbp], edi
mov DWORD PTR -8[rbp], esi
mov DWORD PTR -12[rbp], edx
mov DWORD PTR -16[rbp], ecx
mov DWORD PTR -20[rbp], r8d
mov DWORD PTR -24[rbp], r9d
mov DWORD PTR -24[rbp], 8
mov DWORD PTR 16[rbp], 3 ; HERE
mov DWORD PTR 24[rbp], 9 ; HERE
mov DWORD PTR 32[rbp], 12
mov eax, DWORD PTR 16[rbp]
pop rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size f, .-f
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mov rbp, rsp
.cfi_def_cfa_register 6
push 9
push 8
push 7
mov r9d, 6
mov r8d, 5
mov ecx, 4
mov edx, 3
mov esi, 2
mov edi, 1
call f
add rsp, 24
mov eax, 0
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (Debian 12.2.0-14) 12.2.0"
.section .note.GNU-stack,"",@progbits
My fragment of interest is:
mov DWORD PTR 16[rbp], 3
mov DWORD PTR 24[rbp], 9
The difference between 7th and 8th argument is 8 bytes, whereas the parameters from registers are saved in local memory as 4-byte values. However, all arguments are integers. Why parameters are pushed on stack using 8-byte space?
What I have found up to this moment is page 17 from V ABI. However I am not sure, why does it happen.