Extra 8 bytes on stack in gcc 4.3 (64-bit)

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

 



When I use gcc -S in an x86-64 environment running in 64-bit mode on the
following C function:

int main( void )
{
        long    sum = foo( 3, 4, 5, 6, 7 );
}

gcc-4.1 allocates 16 bytes on the stack for the local variable, sum (my
comments added):

main:
.LFB3:
        pushq %rbp        # save caller base pointer
.LCFI2:
        movq %rsp, %rbp   # establish our base pointer
.LCFI3:
        subq $16, %rsp    # space for local variable
.LCFI4:
        movl $7, %r8d     # pass 5th argument
       .........

The ABI specifies that the stack pointer will be "16-byte aligned at
process entry." So even though sum only takes 8 bytes (longs in 64-bit
mode are 8 bytes), I assume that the compiler allocates 16 bytes to
maintain the 16-byte alignment. 


But with gcc-4.3 I get 24 bytes:
main:
.LFB3:
       pushq %rbp        # save caller base pointer
.LCFI2:
       movq %rsp, %rbp   # establish our base pointer
.LCFI3:
       subq $24, %rsp    # space for local variable
.LCFI4:
       movl $7, %r8d     # pass 5th argument
       .........

Now the stack is no longer 16-byte aligned. Furthermore, this stack
alignment could have been accomplished by allocating only the 8 bytes
needed for the local variable, sum.

What am I missing here?

--Bob



[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