From owner-freebsd-current@FreeBSD.ORG Mon May 28 00:58:31 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id F1A9216A4D1 for ; Mon, 28 May 2007 00:58:31 +0000 (UTC) (envelope-from kabaev@gmail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.233]) by mx1.freebsd.org (Postfix) with ESMTP id 9789C13C45E for ; Mon, 28 May 2007 00:58:31 +0000 (UTC) (envelope-from kabaev@gmail.com) Received: by wx-out-0506.google.com with SMTP id h28so937630wxd for ; Sun, 27 May 2007 17:58:30 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer:mime-version:content-type; b=qxZkfXPXXp5JbezLoulcC2XlXLICd9In+GrawAEm27PCSbRBYGZP4CiVLlHQoIOl5KERxjSI9iV8GRHqSHl5kYVdLkx/+n5YoxNVSL8VXd3n8bY3T+Q8ifGvjlHLrEeaH7aFqZz762MCvULFgW9CVAhi37bNKjtDee1Md1RHwMo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer:mime-version:content-type; b=VjOcGoajqa15Hw07wG7ae5WSOPRzBcIB/tiBQf4QXBA6P8vxt1v+zhGGoBAjrnA52fCp3Dviay3nfzHInp/M/IlLYkIpQusrOa6/98vNG1aRiJG2F9yh2adn2aPXnqAlyiagRxyzAguKHdAhJR6UZ6xkEMwictkHcFbztBRA7S0= Received: by 10.70.123.14 with SMTP id v14mr7574843wxc.1180313910792; Sun, 27 May 2007 17:58:30 -0700 (PDT) Received: from kan.dnsalias.net ( [24.34.98.164]) by mx.google.com with ESMTP id i14sm6584916wxd.2007.05.27.17.58.29; Sun, 27 May 2007 17:58:29 -0700 (PDT) Date: Sun, 27 May 2007 20:58:24 -0400 From: Alexander Kabaev To: Steve Kargl Message-ID: <20070527205824.481fc981@kan.dnsalias.net> In-Reply-To: <20070527193929.GA80582@troutmask.apl.washington.edu> References: <20070526193128.GB54875@troutmask.apl.washington.edu> <20070526190023.C98508@volatile.chemikals.org> <20070526233116.GA56054@troutmask.apl.washington.edu> <200705271053.10725.shoesoft@gmx.net> <20070527151840.GA73374@troutmask.apl.washington.edu> <20070527192825.GA79242@rot13.obsecurity.org> <20070527193929.GA80582@troutmask.apl.washington.edu> X-Mailer: Claws Mail 2.9.1 (GTK+ 2.10.12; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: multipart/signed; boundary=Sig_acUmHozZMaz_0w8xIPpX8Vm; protocol="application/pgp-signature"; micalg=PGP-SHA1 Cc: Ed, freebsd-current@freebsd.org, Schouten , Stefan Ehmann , Kris Kennaway Subject: Re: HEADS-UP: gcc-4.2 import appears to miscompile libm. X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 May 2007 00:58:32 -0000 --Sig_acUmHozZMaz_0w8xIPpX8Vm Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Sun, 27 May 2007 12:39:29 -0700 Steve Kargl wrote: > On Sun, May 27, 2007 at 03:28:25PM -0400, Kris Kennaway wrote: > > On Sun, May 27, 2007 at 08:18:40AM -0700, Steve Kargl wrote: > >> On Sun, May 27, 2007 at 10:53:09AM +0200, Stefan Ehmann wrote: > >>> On Sunday 27 May 2007 01:31:16 Steve Kargl wrote: > >>>> On Sat, May 26, 2007 at 07:09:16PM -0400, Wes Morgan wrote: > >>>>> Working from -O towards -O2 based on the info pages, I can > >>>>> "reproduce" the problem with "-O -fstrict-aliasing -fgcse"... > >>>>> However, -O2 with -fno-strict-aliasing by itself seems to work > >>>>> around the issue. At first glance it looks like a possible > >>>>> interaction between several optimizations. > >>>> > >>>> Ths patch fixes the problem. > >>>> > >>>> --- s_frexpf.c.orig Sat May 26 16:26:50 2007 > >>>> +++ s_frexpf.c Sat May 26 16:28:03 2007 > >>>> @@ -39,6 +39,9 @@ > >>>> } > >>>> *eptr +=3D (ix>>23)-126; > >>>> hx =3D (hx&0x807fffff)|0x3f000000; > >>>> +#if 0 > >>>> *(int*)&x =3D hx; > >>>> +#endif > >>>> + SET_FLOAT_WORD(x,hx); > >>>> return x; > >>>> } > >>>=20 > >>> -fno-strict-aliasing is used by default for me (i386). Also, if > >>> you use -Wall the compiler outputs a warning. > >>=20 > >> You apparently don't have CFLAGS set in /etc/make.conf. > >>=20 > >>> [root@something /usr/src/lib/msun/src]# cc -O2 -Wall -pipe -c > >>> s_frexpf.c s_frexpf.c: In function 'frexpf': > >>> s_frexpf.c:42: warning: dereferencing type-punned pointer will > >>> break strict-aliasing rules > >>=20 > >> Yes, I know. > >>=20 > >> OTOH, the above patch actually fixes the problem, and libm can then > >> be compiled without -fno-strict-aliasing. > >=20 > > OK, so just to confirm, it's not a miscompilation as originally > > suggested, but a code bug? > >=20 >=20 > Yes, it is a code bug. It is my understanding that C (C99?)=20 > considers "*(int*)&x =3D hx;" to be undefined behavior. From > what I've gleaned from the gcc IRC channel, gcc-4.2 now does > a "load and store" instead of a "store and load" (or vice versa). >=20 > Of course, the patch touches libm so be prepared to be brucified. >=20 That is more or less classic example of broken strict aliasing expectations. Thank you for finding it. --=20 Alexander Kabaev --Sig_acUmHozZMaz_0w8xIPpX8Vm Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFGWikwQ6z1jMm+XZYRAuynAJ9KlDka+C72VXj9yijJO7VPp9rBcQCfYmTu gcveXoWGWTSg1OSqpuXdpwI= =XVr+ -----END PGP SIGNATURE----- --Sig_acUmHozZMaz_0w8xIPpX8Vm--