From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15485 invoked by alias); 13 Jun 2012 15:50:45 -0000 Received: (qmail 15454 invoked by uid 22791); 13 Jun 2012 15:50:41 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,TW_VT,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 13 Jun 2012 15:50:27 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5DFoRAL009949 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Jun 2012 11:50:27 -0400 Received: from host2.jankratochvil.net (ovpn-116-33.ams2.redhat.com [10.36.116.33]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q5DFoKhU025200 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Wed, 13 Jun 2012 11:50:23 -0400 Date: Wed, 13 Jun 2012 15:50:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch 2/3] Align stack for SSE (PR tdep/14222) Message-ID: <20120613155020.GB26214@host2.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-06/txt/msg00418.txt.bz2 Hi, this is mostly independent patch. But it does not make sense to discuss alignment in [patch 3/3] when it has been already broken. http://groups.google.com/group/ia32-abi/browse_thread/thread/4f9b3e5069943bf1 says that gcc-4.6 aligns stack to 32 bytes. I do not see it anywhere: 80482e8: 83 e4 f0 and $0xfffffff0,%esp It is aligned just to 16 bytes. Also checked that Intel CPU documentation does not require any more alignment than 16 bytes (sure it may be less effective but traps never occur). Therefore I consider amd64-tdep.c to be correct and I have not changed its existing 16-bytes alignment. No regressions on {x86_64,x86_64-m32,i686}-fedora17-linux-gnu. Thanks, Jan gdb/ 2012-06-13 Jan Kratochvil PR tdep/14222 * i386-tdep.c (i386_push_dummy_call): Align to 16 bytes unconditionally. gdb/testsuite/ 2012-06-13 Jan Kratochvil PR tdep/14222 * gdb.arch/i386-sse-stack-align.S: New file. * gdb.arch/i386-sse-stack-align.c: New file. * gdb.arch/i386-sse-stack-align.exp: New file. --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -2399,9 +2399,11 @@ i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function, if (!write_pass) { - if (have_16_byte_aligned_arg) - args_space = align_up (args_space, 16); sp -= args_space; + + /* ABI (since gcc-4.6?) says that caller should have SP aligned on + a 16 byte boundary. */ + sp &= ~0xf; } } --- /dev/null +++ b/gdb/testsuite/gdb.arch/i386-sse-stack-align.S @@ -0,0 +1,214 @@ +/* Copyright 2012 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* + gcc -S -o gdb.arch/i386-sse-stack-align.{S,c} -Wall -m32 -msse + */ + + .file "i386-sse-stack-align.c" + .text + .type foo, @function +foo: +.LFB0: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset 5, -8 + movl %esp, %ebp + .cfi_def_cfa_register 5 + subl $40, %esp + movaps %xmm0, -24(%ebp) + movaps %xmm1, -40(%ebp) + movaps -24(%ebp), %xmm0 + movaps -40(%ebp), %xmm1 + mulps %xmm1, %xmm0 + addps -24(%ebp), %xmm0 + leave + .cfi_restore 5 + .cfi_def_cfa 4, 4 + ret + .cfi_endproc +.LFE0: + .size foo, .-foo + .type f, @function +f: +.LFB1: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset 5, -8 + movl %esp, %ebp + .cfi_def_cfa_register 5 + subl $40, %esp + movaps .LC0, %xmm0 + movaps %xmm0, -24(%ebp) + movaps -24(%ebp), %xmm1 + movaps -24(%ebp), %xmm0 + call foo + movaps %xmm0, -40(%ebp) + leal -40(%ebp), %eax + movss (%eax), %xmm0 + cvttss2si %xmm0, %eax + leave + .cfi_restore 5 + .cfi_def_cfa 4, 4 + ret + .cfi_endproc +.LFE1: + .size f, .-f + .type g0, @function +g0: +.LFB2: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset 5, -8 + movl %esp, %ebp + .cfi_def_cfa_register 5 + subl $8, %esp + call f + leave + .cfi_restore 5 + .cfi_def_cfa 4, 4 + ret + .cfi_endproc +.LFE2: + .size g0, .-g0 + .type g1, @function +g1: +.LFB3: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset 5, -8 + movl %esp, %ebp + .cfi_def_cfa_register 5 + subl $8, %esp + call f + leave + .cfi_restore 5 + .cfi_def_cfa 4, 4 + ret + .cfi_endproc +.LFE3: + .size g1, .-g1 + .type g2, @function +g2: +.LFB4: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset 5, -8 + movl %esp, %ebp + .cfi_def_cfa_register 5 + subl $8, %esp + call f + leave + .cfi_restore 5 + .cfi_def_cfa 4, 4 + ret + .cfi_endproc +.LFE4: + .size g2, .-g2 + .type g3, @function +g3: +.LFB5: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset 5, -8 + movl %esp, %ebp + .cfi_def_cfa_register 5 + subl $8, %esp + call f + leave + .cfi_restore 5 + .cfi_def_cfa 4, 4 + ret + .cfi_endproc +.LFE5: + .size g3, .-g3 + .type g4, @function +g4: +.LFB6: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset 5, -8 + movl %esp, %ebp + .cfi_def_cfa_register 5 + subl $8, %esp + call f + leave + .cfi_restore 5 + .cfi_def_cfa 4, 4 + ret + .cfi_endproc +.LFE6: + .size g4, .-g4 + .globl main + .type main, @function +main: +.LFB7: + .cfi_startproc + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset 5, -8 + movl %esp, %ebp + .cfi_def_cfa_register 5 + pushl %ebx + andl $-16, %esp + subl $16, %esp + .cfi_offset 3, -12 + call g0 + movl %eax, %ebx + movl $1, (%esp) + call g1 + addl %eax, %ebx + movl $2, 4(%esp) + movl $1, (%esp) + call g2 + addl %eax, %ebx + movl $3, 8(%esp) + movl $2, 4(%esp) + movl $1, (%esp) + call g3 + addl %eax, %ebx + movl $4, 12(%esp) + movl $3, 8(%esp) + movl $2, 4(%esp) + movl $1, (%esp) + call g4 + addl %ebx, %eax + movl -4(%ebp), %ebx + leave + .cfi_restore 5 + .cfi_def_cfa 4, 4 + .cfi_restore 3 + ret + .cfi_endproc +.LFE7: + .size main, .-main + .section .rodata + .align 16 +.LC0: + .long 1065353216 + .long 1073741824 + .long 1077936128 + .long 1082130432 + .ident "GCC: (GNU) 4.6.4 20120612 (prerelease)" + .section .note.GNU-stack,"",@progbits --- /dev/null +++ b/gdb/testsuite/gdb.arch/i386-sse-stack-align.c @@ -0,0 +1,70 @@ +/* Copyright 2012 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +typedef float V __attribute__((vector_size(16))); + +static V +foo (V a, V b) +{ + return a + b * a; +} + +static __attribute__((noinline, noclone)) int +f (void) +{ + volatile V a = { 1, 2, 3, 4 }; + volatile V b; + + b = foo (a, a); + return b[0]; +} + +static __attribute__((noinline, noclone)) int +g0 (void) +{ + return f (); +} + +static __attribute__((noinline, noclone)) int +g1 (int p1) +{ + return f (); +} + +static __attribute__((noinline, noclone)) int +g2 (int p1, int p2) +{ + return f (); +} + +static __attribute__((noinline, noclone)) int +g3 (int p1, int p2, int p3) +{ + return f (); +} + +static __attribute__((noinline, noclone)) int +g4 (int p1, int p2, int p3, int p4) +{ + return f (); +} + +int +main (void) +{ + return g0 () + g1 (1) + g2 (1, 2) + g3 (1, 2, 3) + g4 (1, 2, 3, 4); +} --- /dev/null +++ b/gdb/testsuite/gdb.arch/i386-sse-stack-align.exp @@ -0,0 +1,60 @@ +# Copyright 2012 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +if ![is_x86_like_target] { + verbose "Skipping x86 SSE stack alignment tests." + return +} + +set testfile "i386-sse-stack-align" +set srcfile ${testfile}.S +set csrcfile ${testfile}.c +set executable ${testfile} +set binfile ${objdir}/${subdir}/${executable} +set opts {} + +if [info exists COMPILE] { + set srcfile ${csrcfile} + lappend opts debug optimize=-O2 additional_flags=-msse +} + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $opts] != "" } { + unsupported "cannot compile ${srcfile}" + return -1 +} + +clean_restart $executable + +if ![runto_main] then { + return -1 +} + +set args "" +foreach i {0 1 2 3 4} { + set test "print g$i ($args)" + gdb_test_multiple $test $test { + -re " = 2\r\n$gdb_prompt $" { + pass $test + } + -re "Program received signal SIGSEGV, Segmentation fault\\..*\r\n$gdb_prompt $" { + fail $test + } + } + + if {$args != ""} { + set args "$args, " + } + set args "$args[expr $i + 1]" +}