Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941862AbcJSQLU (ORCPT ); Wed, 19 Oct 2016 12:11:20 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:60830 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S941696AbcJSOVG (ORCPT ); Wed, 19 Oct 2016 10:21:06 -0400 Date: Wed, 19 Oct 2016 11:13:47 +0200 From: Peter Zijlstra To: Richard Biener Cc: "Luis R. Rodriguez" , Vegard Nossum , Jiri Slaby , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Linus Torvalds , stable@vger.kernel.org, Ming Lei , Steven Rostedt , "H. Peter Anvin" , Josh Poimboeuf , Cesar Eduardo Barros , Michael Matz , David Miller , Guenter Roeck , Fengguang Wu , Borislav Petkov , Boris Ostrovsky , Juergen Gross , Kees Cook , Arnaldo Carvalho de Melo , Ingo Molnar , Thomas Gleixner Subject: Re: [PATCH 01/12] extarray: define helpers for arrays defined in linker scripts Message-ID: <20161019091347.GE3102@twins.programming.kicks-ass.net> References: <20161016151616.31451-1-vegard.nossum@oracle.com> <20161016151616.31451-2-vegard.nossum@oracle.com> <20161017083315.GA29322@worktop.vlan200.pylonone.local> <186f8242-3f8d-31cd-a8e8-9743bbc1c1fd@suse.cz> <20161017090930.GT3142@twins.programming.kicks-ass.net> <55e00c01-2da8-8d06-1d05-9ebf775736ec@oracle.com> <20161017114517.GQ3117@twins.programming.kicks-ass.net> <55b3cbe0-f8fc-6505-411d-5f050d3414cc@oracle.com> <20161018211803.GV8651@wotan.suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1265 Lines: 34 On Wed, Oct 19, 2016 at 10:18:43AM +0200, Richard Biener wrote: > The commit implements a long-standing failure to optimize trivial pointer > comparisons that arise for example from libstdc++. PR65686 contains > a simple C example: > > mytype f(struct S *e) > { > mytype x; > if(&x != e->pu) > __builtin_memcpy(&x, e->pu, sizeof(unsigned)); > return x; > } > > where GCC before the commit could not optimize the &x != e->pu test > as trivial false. Which is fine; x is stack based and could not possibly have been handed as the argument to this same function. This is also an entirely different class of optimizations than the whole pointer arithmetic is only valid inside an object thing. The kernel very much relies on unbounded pointer arithmetic, including overflow. Sure, C language says its UB, but we know our memory layout, and it would be very helpful if we could define it. Can't we get a knob extending -fno-strict-aliasing to define pointer arithmetic outside of objects and overflow? I mean, we already use that, we also use -fno-strict-overflow and a whole bunch of others. At the very least, it would be nice to get a -W flag for when this alias analysis stuff kills something so we can at least know when GCC goes and defeats us.