From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/3799 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Solving the recursive memcpy/memset/etc. issue Date: Thu, 1 Aug 2013 22:52:44 -0400 Message-ID: <20130802025244.GM221@brightrain.aerifal.cx> References: <20130801004940.GA20323@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1375411977 14250 80.91.229.3 (2 Aug 2013 02:52:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 2 Aug 2013 02:52:57 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-3803-gllmg-musl=m.gmane.org@lists.openwall.com Fri Aug 02 04:52:59 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1V55UA-00010x-Qw for gllmg-musl@plane.gmane.org; Fri, 02 Aug 2013 04:52:58 +0200 Original-Received: (qmail 3174 invoked by uid 550); 2 Aug 2013 02:52:57 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 3166 invoked from network); 2 Aug 2013 02:52:56 -0000 Content-Disposition: inline In-Reply-To: <20130801004940.GA20323@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:3799 Archived-At: On Wed, Jul 31, 2013 at 08:49:40PM -0400, Rich Felker wrote: > OK, so now that it's hit us for real, what should we do about GCC > generating code for memcpy, memset, etc. which might contain infinite > recursion? Aside from the ARM issue (which was separate), we know the > option causing this bad code generation, and it can be disabled via > -fno-tree-loop-distribute-patterns. However, if GCC policy is that > they consider the compiler entitled to generate calls to > memcpy/memset/memmove/memcmp whenever it wants, then we're just going > to be playing whack-a-mole. For now, I solved it with just this option, and also added some more asm for x86[_64]. > The only fully viable option I see is replacing the code for these > functions with code that uses volatile objects so as to make > optimization utterly impossible. This will of course make them > incredibly slow, but at least we would have safe, working C code, and > we could add asm for each supported arch. I'd actually like to experiment with some ideas for volatile that don't make the C slow. If the compiler really honors volatile, it seems like you can write C code in such a way where the compiler has to implement it pretty close to the abstract machine -- but you can be selective about it, so as to allow the compiler some freedom. > An alternative might be to test the compiler in configure to determine > if, with the selected CFLAGS, it generates recursive code for these > functions, and if so, defining a macro that causes musl to revert to > the volatile code. This is not in the workaround I committed, but could be added.. Rich