From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 14 09:01:55 2011 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8E5B4106566B for ; Fri, 14 Jan 2011 09:01:55 +0000 (UTC) (envelope-from peter.blok@bsd4all.org) Received: from relay10.prolocation.net (relay10.prolocation.net [IPv6:2a00:d00:ff:133:94:228:133:100]) by mx1.freebsd.org (Postfix) with ESMTP id C46F48FC24 for ; Fri, 14 Jan 2011 09:01:54 +0000 (UTC) Received: from cust-95-128-94-66.breedbanddelft.nl ([95.128.94.66] helo=mail.bsd4all.org) by relay10.prolocation.net with esmtp (Exim 4.69) (envelope-from ) id 1PdfXe-0005uX-2o; Fri, 14 Jan 2011 10:01:54 +0100 Received: from mailgw (mailgw [192.168.10.12]) by mail.bsd4all.org (Postfix) with ESMTP id 493381152E; Fri, 14 Jan 2011 10:01:48 +0100 (CET) X-Virus-Scanned: amavisd-new at bsd4all.org Received: from mail.bsd4all.org ([192.168.10.1]) by mailgw (fwgw.homebrew.bsd4all.org [192.168.10.12]) (amavisd-new, port 10024) with ESMTP id RUChvQgXCzZG; Fri, 14 Jan 2011 10:01:36 +0100 (CET) Received: from bsd4all.org (adexlinge10 [192.168.10.16]) by mail.bsd4all.org (Postfix) with ESMTP id 42275114B0; Fri, 14 Jan 2011 10:01:36 +0100 (CET) Received: from 128.222.37.58 ([128.222.37.58]) by adexlinge10.LINGE10.local ([192.168.10.16]) with Microsoft Exchange Server HTTP-DAV ; Fri, 14 Jan 2011 08:58:35 +0000 User-Agent: Microsoft-Entourage/12.26.0.100708 Date: Fri, 14 Jan 2011 09:52:34 +0100 From: Peter Blok To: Warner Losh , Message-ID: Thread-Topic: What does the FreeBSD/i386 ABI say about stack alignment? Thread-Index: AcuzyGKkPQk+EXqxs0KcmFccelbB7A== In-Reply-To: <4D2F8BFE.9070607@bsdimp.com> Mime-version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: Re: What does the FreeBSD/i386 ABI say about stack alignment? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Jan 2011 09:01:55 -0000 Hi, I=B9m probably missing something but if you require a stack variable to be aligned why not use a type attribute like __attribute__ ((aligned (8))) Peter On 1/14/11 00:34 AM, "Warner Losh" wrote: > On 01/13/2011 13:28, Kostik Belousov wrote: >> > On Thu, Jan 13, 2011 at 12:19:00PM -0500, Ryan Stone wrote: >>> >> I've been trying to get an application compiled with gcc 4.5.1 runni= ng >>> >> on FreeBSD 8.1, but it's been crashing during startup with a SIGBUS. >>> >> It turns out that the problem is that gcc is issuing SSE >>> >> instructions(in my case, a movdqa) that assume that the stack will b= e >>> >> aligned to a 16-byte boundary. It seems that Linux/i386 guarantees >>> >> this, and I worry that gcc has extended this assumption to all i386 >>> >> architectures. I'm assuming that FreeBSD doesn't make any such >>> >> promises based on the fact that I'm getting crashes. >>> >> >>> >> There does seem to be a flag (-mstackrealign) that you can set to >>> >> force gcc to align the stack to what it wants, but that pessimizes t= he >>> >> generated code a bit. Some googling would seem to indicate that >>> >> -mpreferred-stack-boundary won't always handle this problem correctl= y. >>> >> >>> >> Any ideas? My inclination, at least for our local source tree here = at >>> >> $WORK, would be to accommodate gcc and guarantee the stack alignment >>> >> that it wants rather than pessimize our application. It seems we ha= ve >>> >> an old local patch/hack in our FreeBSD 6.1 tree(apparently based on >>> >> this:=20 >>> http://www.freebsd.org/cgi/getmsg.cgi?fetch=3D438552+0+/usr/local/www/db/= text/ >>> 2000/freebsd-current/20000507.freebsd-current). >>> >> I believe that this patch is the reason why we haven't seen the >>> >> problem when running on 6.1, but the patch doesn't seem to work >>> >> anymore on 8.1. >> > Look at lib/csu/i386-elf/crt1_s.S, we align stack on startup. >> > My understanding is that the requirement is (%esp& 0xf) =3D=3D 0 just bef= ore >> > the call to the function. And we are off by 4 (this is my fault). >> > >> > Please give this a try. >> > >> > diff --git a/lib/csu/i386-elf/crt1_s.S b/lib/csu/i386-elf/crt1_s.S >> > index d7ed0a2..17ac0e3 100644 >> > --- a/lib/csu/i386-elf/crt1_s.S >> > +++ b/lib/csu/i386-elf/crt1_s.S >> > @@ -42,6 +42,7 @@ _start: >> > .cfi_def_cfa_register %ebp >> > andl $0xfffffff0,%esp # align stack >> > leal 8(%ebp),%eax >> > + subl $4,%esp >> > pushl %eax # argv >> > pushl 4(%ebp) # argc >> > pushl %edx # rtld cleanup >=20 > I'm seeing weird core dumps for ssh and friends on i386 on stable/8 from > a few days ago. Could that be related? >=20 > Warner >=20 > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org= "