From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12965 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] optimize explicit_bzero for size Date: Thu, 28 Jun 2018 15:35:47 -0400 Message-ID: <20180628193547.GI1392@brightrain.aerifal.cx> References: <20180628175729.4391-1-amonakov@ispras.ru> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1530214436 2399 195.159.176.226 (28 Jun 2018 19:33:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 28 Jun 2018 19:33:56 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12981-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jun 28 21:33:52 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1fYcfw-0000Yf-BF for gllmg-musl@m.gmane.org; Thu, 28 Jun 2018 21:33:52 +0200 Original-Received: (qmail 19936 invoked by uid 550); 28 Jun 2018 19:36:00 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 19910 invoked from network); 28 Jun 2018 19:35:59 -0000 Content-Disposition: inline In-Reply-To: <20180628175729.4391-1-amonakov@ispras.ru> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12965 Archived-At: On Thu, Jun 28, 2018 at 08:57:29PM +0300, Alexander Monakov wrote: > Avoid saving/restoring the incoming argument by reusing memset return value. > --- > > I think it's unfortunate that the commit adding explicit_bzero does not say > the rationale for the magic empty asm; LTO being the "obvious" explanation, > of course, IMHO is not a reason to omit the explanation. LTO is the only plausible "mechanical" reason I know of, but formally it's just about producing a dependency on the stores. > Does it imply an > intention to support LTO, Yes, that's always been the intention. Last I checked there was a linker-side bug whereby LTO broke crt1.c (due to failure to consider the reference from the file-scope asm) which we might want to workaround by forcibly disabling LTO for startfiles, but the intent is that everything in musl be correct without relying on extern calls as some sort of magic barriers. > and if so, would other magic asms elsewhere be > accepted if they help with LTO issues? Ideally no -- explicit_bzero is special because its whole purpose is to do something that doesn't really make sense in the abstract model of the language, but that's nonetheless desired for real-world hardening. I'm not aware of anything else like that. If there are places where there's a real problem caused by "lack of barriers" with LTO, we should first try to fix it in a way that's correct with regard to the abstract model, I think. > src/string/explicit_bzero.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/src/string/explicit_bzero.c b/src/string/explicit_bzero.c > index 3d270040..f2e12f23 100644 > --- a/src/string/explicit_bzero.c > +++ b/src/string/explicit_bzero.c > @@ -3,6 +3,6 @@ > > void explicit_bzero(void *d, size_t n) > { > - memset(d, 0, n); > + d = memset(d, 0, n); > __asm__ __volatile__ ("" : : "r"(d) : "memory"); > } > -- > 2.11.0 Or if you like it: - memset(d, 0, n); - __asm__ __volatile__ ("" : : "r"(d) : "memory"); + __asm__ __volatile__ ("" : : "r"(memset(d, 0, n)) : "memory"); Not sure if this is nice or hideous... ;-) Rich