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>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --] 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)). >>> >>> When you compile and run it like this on FreeBSD/i386, it results in a >>> SIGBUS: >>> >>> % cc -o paddd paddd.c -O3 -msse2 -fPIE -fomit-frame-pointer >>> % ./paddd >>> Bus error >>> >>> The reason is this instruction where %esp isn't 16-byte aligned: >>> paddd (%esp), %xmm7 > > Hmm, as far as I can see, the problem is related to position independent > code, in combination with omitting the frame pointer: > > $ cc -o paddd paddd.c -O3 -msse2 -fomit-frame-pointer > $ ./paddd > $ > > $ cc -o paddd paddd.c -O3 -msse2 -fPIE -fomit-frame-pointer > $ ./paddd > Bus error (core dumped) > $ > > $ cc -o paddd paddd.c -O3 -msse2 -fPIE -fno-omit-frame-pointer > $ ./paddd > $ 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=12250 which seems like the same bug (but on Solaris). [-- Attachment #2 --] -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (FreeBSD) iF4EAREIAAYFAlI7OsQACgkQfoCS2CCgtivdNQD/dTMP9mbydFH/nyziZ44nOzvk G4HPKnw7Buh6gnYieAQA/RO5CY1fub5Ivrj8A8lrGNIQ2Lh/dollSCvMbARI59sp =9A9p -----END PGP SIGNATURE-----help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130919195615.5040b4cb>
