public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/60926] New: Compiler doesn't properly align stack pointer
@ 2014-04-22 21:08 gidici61 at gmail dot com
2014-04-22 21:29 ` [Bug target/60926] " gidici61 at gmail dot com
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: gidici61 at gmail dot com @ 2014-04-22 21:08 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
Bug ID: 60926
Summary: Compiler doesn't properly align stack pointer
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: trivial
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: gidici61 at gmail dot com
Assembly code of the sample C code:
int g2(int p1) { return p1; }
int g1(int p1) { return g2(p1); }
int main() { return g1(65); }
when compiled [¹] on Debian wheezy using gcc v.4.7.2 shows that register rsp is
not 16 byte aligned before calling g2():
g1:
pushq %rbp
movq %rsp, %rbp
subq $8, %rsp ; why 8?
movl %edi, -4(%rbp)
movl -4(%rbp), %eax
movl %eax, %edi
call g2
leave
ret
[¹] gcc -S filename.c
>From gcc-bugs-return-449611-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Apr 22 21:11:45 2014
Return-Path: <gcc-bugs-return-449611-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 13197 invoked by alias); 22 Apr 2014 21:11:45 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 13176 invoked by uid 48); 22 Apr 2014 21:11:43 -0000
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/60926] Compiler doesn't properly align stack pointer
Date: Tue, 22 Apr 2014 21:11:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 4.7.2
X-Bugzilla-Keywords:
X-Bugzilla-Severity: trivial
X-Bugzilla-Who: pinskia at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status resolution
Message-ID: <bug-60926-4-AddCAMaTEy@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60926-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60926-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-04/txt/msg01631.txt.bz2
Content-length: 590
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> pushq %rbp
> movq %rsp, %rbp
> subq $8, %rsp ; why 8?
Because the pushq increments rsp by 8 so adding another 8 will cause it to be
full addition of 16.
>From gcc-bugs-return-449613-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Apr 22 21:13:25 2014
Return-Path: <gcc-bugs-return-449613-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 15023 invoked by alias); 22 Apr 2014 21:13:25 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 14568 invoked by uid 55); 22 Apr 2014 21:13:21 -0000
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/58880] [4.9/4.10 Regression] [OOP] ICE on valid with FINAL function and type extension
Date: Tue, 22 Apr 2014 21:13:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: fortran
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords: ice-on-valid-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: burnus at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P4
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.9.1
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-58880-4-n82ToTTYu7@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-58880-4@http.gcc.gnu.org/bugzilla/>
References: <bug-58880-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-04/txt/msg01633.txt.bz2
Content-length: 1016
http://gcc.gnu.org/bugzilla/show_bug.cgi?idX880
--- Comment #15 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Author: burnus
Date: Tue Apr 22 21:12:46 2014
New Revision: 209662
URL: http://gcc.gnu.org/viewcvs?rev 9662&root=gcc&view=rev
Log:
2014-04-22 Tobias Burnus <burnus@net-b.de>
Backport from mainline
2014-04-11 Tobias Burnus <burnus@net-b.de>
PR fortran/58880
PR fortran/60495
* resolve.c (gfc_resolve_finalizers): Ensure that vtables
and finalization wrappers are generated.
2014-04-22 Tobias Burnus <burnus@net-b.de>
Backport from mainline
2014-04-11 Tobias Burnus <burnus@net-b.de>
PR fortran/58880
PR fortran/60495
* gfortran.dg/finalize_25.f90: New.
Added:
branches/gcc-4_9-branch/gcc/testsuite/gfortran.dg/finalize_25.f90
Modified:
branches/gcc-4_9-branch/gcc/fortran/ChangeLog
branches/gcc-4_9-branch/gcc/fortran/resolve.c
branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/60926] Compiler doesn't properly align stack pointer
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
@ 2014-04-22 21:29 ` gidici61 at gmail dot com
2014-04-22 21:31 ` pinskia at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: gidici61 at gmail dot com @ 2014-04-22 21:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
--- Comment #2 from gidici61 at gmail dot com ---
Register rsp is correctly aligned before "call g1"; let's assume rsp=0xB0.
"call g1" pushes rip (8 bytes) on the stack. Now rsp=0xA8.
Then "pushq %rbp" subtracts 8. Now rsp=0xA0.
"subq $8, %rsp" subtracts 8. Now rsp=0x98
So before calling g2() rsp is not properly aligned.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/60926] Compiler doesn't properly align stack pointer
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
2014-04-22 21:29 ` [Bug target/60926] " gidici61 at gmail dot com
@ 2014-04-22 21:31 ` pinskia at gcc dot gnu.org
2014-04-22 21:42 ` gidici61 at gmail dot com
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-04-22 21:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to gidici61 from comment #2)
> Register rsp is correctly aligned before "call g1"; let's assume rsp=0xB0.
> "call g1" pushes rip (8 bytes) on the stack. Now rsp=0xA8.
> Then "pushq %rbp" subtracts 8. Now rsp=0xA0.
> "subq $8, %rsp" subtracts 8. Now rsp=0x98
> So before calling g2() rsp is not properly aligned.
call also pushes onto the stack.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/60926] Compiler doesn't properly align stack pointer
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
2014-04-22 21:29 ` [Bug target/60926] " gidici61 at gmail dot com
2014-04-22 21:31 ` pinskia at gcc dot gnu.org
@ 2014-04-22 21:42 ` gidici61 at gmail dot com
2014-04-22 21:53 ` gidici61 at gmail dot com
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: gidici61 at gmail dot com @ 2014-04-22 21:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
--- Comment #4 from gidici61 at gmail dot com ---
(In reply to Andrew Pinski from comment #3)
> (In reply to gidici61 from comment #2)
> > Register rsp is correctly aligned before "call g1"; let's assume rsp=0xB0.
> > "call g1" pushes rip (8 bytes) on the stack. Now rsp=0xA8.
> > Then "pushq %rbp" subtracts 8. Now rsp=0xA0.
> > "subq $8, %rsp" subtracts 8. Now rsp=0x98
> > So before calling g2() rsp is not properly aligned.
>
> call also pushes onto the stack.
If you add "putchar(p1)" in g2(), then rsp become 16-byte aligned before
calling g2():
int g2(int p1) { putchar(p1); return p1; }
int g1(int p1) { return g2(p1); }
int main() { return g1(65); }
gives the following assembler code:
g1:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp ; OK
movl %edi, -4(%rbp)
movl -4(%rbp), %eax
movl %eax, %edi
call g2
leave
ret
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/60926] Compiler doesn't properly align stack pointer
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
` (2 preceding siblings ...)
2014-04-22 21:42 ` gidici61 at gmail dot com
@ 2014-04-22 21:53 ` gidici61 at gmail dot com
2014-04-25 13:45 ` gidici61 at gmail dot com
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: gidici61 at gmail dot com @ 2014-04-22 21:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
--- Comment #5 from gidici61 at gmail dot com ---
Please see also:
http://stackoverflow.com/questions/22941372/gcc-4-7-2-in-debian-wheezy-doesnt-always-properly-align-stack-pointer-is-this/23055211#23055211
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/60926] Compiler doesn't properly align stack pointer
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
` (3 preceding siblings ...)
2014-04-22 21:53 ` gidici61 at gmail dot com
@ 2014-04-25 13:45 ` gidici61 at gmail dot com
2014-04-25 15:46 ` hjl.tools at gmail dot com
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: gidici61 at gmail dot com @ 2014-04-25 13:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
--- Comment #6 from gidici61 at gmail dot com ---
I don't understand why the addition of "putchar(p1)" in g2() C code changes
"subq $8, %rsp" to "subq $16 %rsp", while all the other assembler code remain
unchanged.
So, if the second ("subq $16 %rsp") makes rsp 16 byte aligned before "call g2",
then the first ("subq $8, %rsp") must be wrong and vice-versa.
Can you help me to understand what I'm missing? Thank you in advance.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/60926] Compiler doesn't properly align stack pointer
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
` (4 preceding siblings ...)
2014-04-25 13:45 ` gidici61 at gmail dot com
@ 2014-04-25 15:46 ` hjl.tools at gmail dot com
2014-04-25 16:26 ` gidici61 at gmail dot com
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2014-04-25 15:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
--- Comment #7 from H.J. Lu <hjl.tools at gmail dot com> ---
Since GCC finds out that g2 only needs 8 byte stack alignment,
it only needs to align stack to 8 byte when calling g2.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/60926] Compiler doesn't properly align stack pointer
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
` (5 preceding siblings ...)
2014-04-25 15:46 ` hjl.tools at gmail dot com
@ 2014-04-25 16:26 ` gidici61 at gmail dot com
2014-04-25 16:30 ` gidici61 at gmail dot com
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: gidici61 at gmail dot com @ 2014-04-25 16:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
--- Comment #8 from gidici61 at gmail dot com ---
(In reply to H.J. Lu from comment #7)
> Since GCC finds out that g2 only needs 8 byte stack alignment,
> it only needs to align stack to 8 byte when calling g2.
Thank you. So this should be an exception? System V ABI x86, par. 3.2.2, page
16, says: "The end of the input argument area shall be aligned on a 16 (32, if
is
passed on stack) byte boundary. In other words, the value (%rsp + 8) is always
a multiple of 16 (32) when control is transferred to the function entry point".
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/60926] Compiler doesn't properly align stack pointer
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
` (6 preceding siblings ...)
2014-04-25 16:26 ` gidici61 at gmail dot com
@ 2014-04-25 16:30 ` gidici61 at gmail dot com
2014-04-25 16:40 ` gidici61 at gmail dot com
2014-04-25 17:45 ` hjl.tools at gmail dot com
9 siblings, 0 replies; 11+ messages in thread
From: gidici61 at gmail dot com @ 2014-04-25 16:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
--- Comment #9 from gidici61 at gmail dot com ---
I apologize. I forgot to specify that I used a 64 bit version of OS.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/60926] Compiler doesn't properly align stack pointer
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
` (7 preceding siblings ...)
2014-04-25 16:30 ` gidici61 at gmail dot com
@ 2014-04-25 16:40 ` gidici61 at gmail dot com
2014-04-25 17:45 ` hjl.tools at gmail dot com
9 siblings, 0 replies; 11+ messages in thread
From: gidici61 at gmail dot com @ 2014-04-25 16:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
--- Comment #10 from gidici61 at gmail dot com ---
(In reply to gidici61 from comment #9)
> I apologize. I forgot to specify that I used a 64 bit version of OS.
I should have written "System V ABi x86-64".
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/60926] Compiler doesn't properly align stack pointer
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
` (8 preceding siblings ...)
2014-04-25 16:40 ` gidici61 at gmail dot com
@ 2014-04-25 17:45 ` hjl.tools at gmail dot com
9 siblings, 0 replies; 11+ messages in thread
From: hjl.tools at gmail dot com @ 2014-04-25 17:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60926
--- Comment #11 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to gidici61 from comment #8)
> (In reply to H.J. Lu from comment #7)
> > Since GCC finds out that g2 only needs 8 byte stack alignment,
> > it only needs to align stack to 8 byte when calling g2.
>
> Thank you. So this should be an exception? System V ABI x86, par. 3.2.2,
It is an optimization.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2014-04-25 17:45 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-22 21:08 [Bug c/60926] New: Compiler doesn't properly align stack pointer gidici61 at gmail dot com
2014-04-22 21:29 ` [Bug target/60926] " gidici61 at gmail dot com
2014-04-22 21:31 ` pinskia at gcc dot gnu.org
2014-04-22 21:42 ` gidici61 at gmail dot com
2014-04-22 21:53 ` gidici61 at gmail dot com
2014-04-25 13:45 ` gidici61 at gmail dot com
2014-04-25 15:46 ` hjl.tools at gmail dot com
2014-04-25 16:26 ` gidici61 at gmail dot com
2014-04-25 16:30 ` gidici61 at gmail dot com
2014-04-25 16:40 ` gidici61 at gmail dot com
2014-04-25 17:45 ` hjl.tools at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).