From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18602 invoked by alias); 10 Apr 2009 03:56:46 -0000 Received: (qmail 18594 invoked by uid 22791); 10 Apr 2009 03:56:46 -0000 X-SWARE-Spam-Status: No, hits=0.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_JMF_BL,SPF_SOFTFAIL X-Spam-Check-By: sourceware.org Received: from xena.cds1.net (HELO mail.cds1.net) (216.174.197.150) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 10 Apr 2009 03:56:41 +0000 Received: from [192.168.1.100] (unknown [192.82.28.137]) by mail.cds1.net (Postfix) with ESMTP id 2050CE89D5ED for ; Thu, 9 Apr 2009 20:56:12 -0700 (PDT) Subject: Extra 8 bytes on stack in gcc 4.3 (64-bit) From: Bob Plantz To: gcc-help Content-Type: text/plain Date: Fri, 10 Apr 2009 03:56:00 -0000 Message-Id: <1239335765.6150.50.camel@bob-desktop.local> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2009-04/txt/msg00113.txt.bz2 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