From owner-freebsd-toolchain@FreeBSD.ORG Thu Sep 19 17:56:29 2013 Return-Path: Delivered-To: toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id EEC8142E; Thu, 19 Sep 2013 17:56:29 +0000 (UTC) (envelope-from tijl@freebsd.org) Received: from mailrelay008.isp.belgacom.be (mailrelay008.isp.belgacom.be [195.238.6.174]) by mx1.freebsd.org (Postfix) with ESMTP id 5D9D32DC5; Thu, 19 Sep 2013 17:56:29 +0000 (UTC) X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmMGANA5O1JR8n3K/2dsb2JhbABbgwc4RsE4gSEXdIIlAQEFViMQCw4KCSUPKh4GE4gHCLopj2cHhB4DkCaHVYEwkEaDJjo Received: from 202.125-242-81.adsl-dyn.isp.belgacom.be (HELO kalimero.tijl.coosemans.org) ([81.242.125.202]) by relay.skynet.be with ESMTP; 19 Sep 2013 19:56:21 +0200 Received: from kalimero.tijl.coosemans.org (kalimero.tijl.coosemans.org [127.0.0.1]) by kalimero.tijl.coosemans.org (8.14.7/8.14.7) with ESMTP id r8JHuKHs004816; Thu, 19 Sep 2013 19:56:20 +0200 (CEST) (envelope-from tijl@FreeBSD.org) Date: Thu, 19 Sep 2013 19:56:15 +0200 From: Tijl Coosemans To: Dimitry Andric Subject: Re: i386 clang optimisation problem with stack alignment Message-ID: <20130919195615.5040b4cb@kalimero.tijl.coosemans.org> In-Reply-To: <9893CCE3-C7EF-4B52-B32E-8F1A0CE022C8@FreeBSD.org> References: <20130910181601.2e89af87@kalimero.tijl.coosemans.org> <20130910183456.175162f7@kalimero.tijl.coosemans.org> <9893CCE3-C7EF-4B52-B32E-8F1A0CE022C8@FreeBSD.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA256; boundary="Sig_/ApJEKIl8CXe_0OC19pEPjg2"; protocol="application/pgp-signature" Cc: toolchain@FreeBSD.org X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Sep 2013 17:56:30 -0000 --Sig_/ApJEKIl8CXe_0OC19pEPjg2 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Wed, 18 Sep 2013 23:13:26 +0200 Dimitry Andric wrote: > On Sep 10, 2013, at 18:34, Tijl Coosemans wrote: >> On Tue, 10 Sep 2013 18:16:01 +0200 Tijl Coosemans wrote: >>> I've attached a small test program extracted from multimedia/gstreamer-= ffmpeg >>> (libavcodec/h264_cabac.c:ff_h264_init_cabac_states(H264Context *h)). >>>=20 >>> When you compile and run it like this on FreeBSD/i386, it results in a >>> SIGBUS: >>>=20 >>> % cc -o paddd paddd.c -O3 -msse2 -fPIE -fomit-frame-pointer=20 >>> % ./paddd >>> Bus error >>>=20 >>> The reason is this instruction where %esp isn't 16-byte aligned: >>> paddd (%esp), %xmm7 >=20 > Hmm, as far as I can see, the problem is related to position independent > code, in combination with omitting the frame pointer: >=20 > $ cc -o paddd paddd.c -O3 -msse2 -fomit-frame-pointer > $ ./paddd > $=20 >=20 > $ cc -o paddd paddd.c -O3 -msse2 -fPIE -fomit-frame-pointer > $ ./paddd > Bus error (core dumped) > $=20 >=20 > $ cc -o paddd paddd.c -O3 -msse2 -fPIE -fno-omit-frame-pointer > $ ./paddd > $=20 Omitting -fPIE frees up a register and that changes the generated code too much to trigger the bug so I'm not sure it has anything to do with it. -fomit-frame-pointer may be part of the problem though. Without a frame pointer that holds the old value of %esp, the stack cannot be realigned because the old value cannot be restored then. It seems clang/LLVM knows this at least partly because with -fomit-frame-pointer it doesn't realign stack and uses movdqu to store a value at (%esp) (instead of movdqa in the -fno-omit-frame-pointer case). Either clang/LLVM shouldn't use instructions like paddd in this case or it should override -fomit-frame-pointer and use a frame pointer whenever the stack needs realigning. I added a comment to http://llvm.org/bugs/show_bug.cgi?id=3D12250 which seems like the same bug (but on Solaris). --Sig_/ApJEKIl8CXe_0OC19pEPjg2 Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (FreeBSD) iF4EAREIAAYFAlI7OsQACgkQfoCS2CCgtivdNQD/dTMP9mbydFH/nyziZ44nOzvk G4HPKnw7Buh6gnYieAQA/RO5CY1fub5Ivrj8A8lrGNIQ2Lh/dollSCvMbARI59sp =9A9p -----END PGP SIGNATURE----- --Sig_/ApJEKIl8CXe_0OC19pEPjg2--