Date: Thu, 19 Sep 2013 19:56:15 +0200 From: Tijl Coosemans <tijl@FreeBSD.org> To: Dimitry Andric <dim@FreeBSD.org> Cc: toolchain@FreeBSD.org 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>
next in thread | previous in thread | raw e-mail | index | archive | help
--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 <tijl@freebsd.org> 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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130919195615.5040b4cb>