Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why pad the stack on a function call?

I was looking at the dissasembly of a function call and found this:

movq    %rsp, %rbp
pushq   %rbx
subq    $136, %rsp        ; Pad the stack
....
addq    $136, %rsp        ; Unpad the stack
popq    %rbx
popq    %rbp
ret

What is the value of doing this?

like image 697
sircodesalot Avatar asked Jun 17 '14 17:06

sircodesalot


1 Answers

That's the space for local variables, not padding.

The compiler will create that stack space for any register spills and local variables it has to store while running this function.

You could see some padding, when disassembling x86-64 code with the SysV ABI (most things that aren't Windows, I don't know how it is in the latter), since function calls have to have the stack aligned at 16 bytes. But in this case it's actually reserving space for local variables.

You might want to look at this or look for more information on how compilers work.

like image 140
filcab Avatar answered Oct 01 '22 06:10

filcab