This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]