Re: Reserve space in stack

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



OK, I understand. But why compiler doesn't use this space in the stack to store some local variables?
For example:

void dummy(char *);

int test (void)
{
  char a[8] = "12345678";
  dummy(a);
  return 0;
}

i got this:

test:
        subq $24, %rsp
        movabsq $4050765991979987505, %rax
        leaq 8(%rsp), %rdi
        movq %rax, 8(%rsp)
        call dummy
        xorl %eax, %eax
        addq $24, %rsp
        ret

It reserved 24 bytes on stack instead reserve and use only 8 byte and storing "12345678" in it

12.04.2016, 11:19, "Florian Weimer" <fweimer@xxxxxxxxxx>:
>  On 04/12/2016 06:34 AM, sztfg@xxxxxxxxx wrote:
>
>>   test:
>>            subq $8, %rsp # why?
>>            call dummy
>>            xorl %eax, %eax
>>            addq $8, %rsp # why?
>>            ret
>>            .size test, .-test
>>
>>   Why need to do this subq addq?
>
>  The x86_64 ABI requires that the stack pointer is a multiple of 16
>  before the CALL instruction is executed. This simplifies code in
>  functions which need to store vector register values on the stack.
>
>  Florian



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux