From owner-freebsd-hackers@FreeBSD.ORG Sun Nov 20 19:16:09 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 9FC1B1065672 for ; Sun, 20 Nov 2011 19:16:09 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-pz0-f44.google.com (mail-pz0-f44.google.com [209.85.210.44]) by mx1.freebsd.org (Postfix) with ESMTP id 744918FC08 for ; Sun, 20 Nov 2011 19:16:09 +0000 (UTC) Received: by pzk33 with SMTP id 33so23637163pzk.3 for ; Sun, 20 Nov 2011 11:16:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=QXdgnlDNH628JVbMh+n8q1ZLGDMBwxnBDoJjk+nXvlc=; b=WmS1d3HJG7jw/I/OHyKl5knK3sajAeBYlx2XqjOyAikQUII6Cu9ni/xdewlAFVqGG5 wi444T2ZVEDfjuuQBH/Ek528Jv9E7B88NaUvsQ/nwt/jRS2YQOW5QxTjmzH6SnHP4YmQ X2X+pajidEDkrR3vp7oHU33D6FF5DfPEFXzcg= MIME-Version: 1.0 Received: by 10.68.33.134 with SMTP id r6mr29219905pbi.76.1321816568945; Sun, 20 Nov 2011 11:16:08 -0800 (PST) Sender: mdf356@gmail.com Received: by 10.68.56.97 with HTTP; Sun, 20 Nov 2011 11:16:08 -0800 (PST) In-Reply-To: <20111120182430.GA1672@reks> References: <20111119100150.GA1560@reks> <20111119161958.GA91681@reks> <20111120182430.GA1672@reks> Date: Sun, 20 Nov 2011 11:16:08 -0800 X-Google-Sender-Auth: YZZvC6iz3cN6Z8l3naB743C5SNg Message-ID: From: mdf@FreeBSD.org To: Gleb Kurtsou Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org Subject: Re: gcc 4.2 miscompilation with -O2 -fno-omit-frame-pointer on amd64 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: Sun, 20 Nov 2011 19:16:09 -0000 On Sun, Nov 20, 2011 at 10:24 AM, Gleb Kurtsou wro= te: > On (19/11/2011 09:11), mdf@FreeBSD.org wrote: >> On Sat, Nov 19, 2011 at 8:19 AM, Gleb Kurtsou w= rote: >> > On (19/11/2011 07:26), mdf@FreeBSD.org wrote: >> >> On Sat, Nov 19, 2011 at 2:01 AM, Gleb Kurtsou wrote: >> >> > Hi, >> >> > >> >> > I was lucky to write a bit of code which gcc 4.2 fails to compile >> >> > correctly with -O2. Too keep long story short the code fails for gc= c >> >> > from base system and last gcc 4.2 snapshot from ports. It works wit= h gcc >> >> > 4.3, gcc 4.4 on FreeBSD and Linux. Clang from base is also good. -O= and >> >> > -Os optimization levels are fine (I've tried with all -f* flags >> >> > mentioned in documentation) >> >> > >> >> > -O2 -fno-omit-frame-pointer combination is troublesome on amd64. I >> >> > presume i386 should be fine. These options are also used for >> >> > compilation of kernel (with debugging enabled) and modules. >> >> > >> >> > I'm not able to share the code, but have a test case reproducing th= e >> >> > bug. I've encountered the issue over a week ago and tried narrowing= it down >> >> > to a simple test I could share but without much success. >> >> > >> >> > The code itself is very common: initialize two structs on stack, ca= ll a >> >> > function with pointers to those stucts as arguments. A number of in= lined >> >> > assertion functions. gcc fails to correctly optimize struct assignm= ents >> >> > with -fno-omit-frame-pointer, I have a number of small structs assi= gned, >> >> > gcc decides not to use data coping but to assign fields directly. I= 've >> >> > tried disabling sra, tweaking sra parameters -- no luck in forcing = it >> >> > to copy data. Replacing one particular assignment with memcpy produ= ces >> >> > correct code, but that's not a solution. >> >> >> >> How small are the structs? =A0gcc has an optimization for structs tha= t >> >> are no larger than a register, but it's buggy in 4.2 and we disabled >> >> it at $WORK. =A0I can dig up the patch if this is the problem. >> > struct sockaddr_in in this particular test. 16 bytes. >> > >> > Register size structs are rather common, e.g. struct in_addr. >> > >> > I could test the patch. Adding -finline-functions seems to fix the iss= ue >> > for me. >> >> I can't find the thing I'm thinking of. =A0The only potentially relevant >> patch I see in our gcc sources is this: > > It could be related but doesn't fix bug I observe. I've installed fresh > 9.0-RC2 virtual machine and reran tests in clean environment. > > Do you plan committing it? We probably should, but I haven't heard that anyone else has had a problem with this. I'm sure when I do the next FreeBSD merge at $WORK I'll re-remember it and probably commit it then. Thanks, matthew >> Index: opts.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> --- opts.c =A0 =A0(.../vendor.branches/freebsd/stable/7/src/contrib/gcc/= opts.c) =A0 (revision >> 211574) >> +++ opts.c =A0 =A0(.../head/src/contrib/gcc/opts.c) =A0 =A0 =A0 (revisio= n 211574) >> @@ -457,11 +457,7 @@ >> =A0 =A0 =A0 =A0flag_tree_dse =3D 1; >> =A0 =A0 =A0 =A0flag_tree_ter =3D 1; >> =A0 =A0 =A0 =A0flag_tree_live_range_split =3D 1; >> + =A0 =A0 =A0/** >> + =A0 =A0 =A0 * 7dot1MERGE: tree-sra in gcc 4.2.x is buggy and >> + =A0 =A0 =A0 * breaks bitfield structs. >> + =A0 =A0 =A0 */ >> + =A0 =A0 =A0flag_tree_sra =3D 0; >> - =A0 =A0 =A0flag_tree_sra =3D 1; >> =A0 =A0 =A0 =A0flag_tree_copyrename =3D 1; >> =A0 =A0 =A0 =A0flag_tree_fre =3D 1; >> =A0 =A0 =A0 =A0flag_tree_copy_prop =3D 1; >> >> Thanks, >> matthew >