From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2806 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH 1/3] protect some clobbered variables with volatile Date: Sun, 17 Feb 2013 12:55:12 -0500 Message-ID: <20130217175512.GE20323@brightrain.aerifal.cx> References: <1360535421.23424.467.camel@eris.loria.fr> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1361123725 26840 80.91.229.3 (17 Feb 2013 17:55:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 17 Feb 2013 17:55:25 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2807-gllmg-musl=m.gmane.org@lists.openwall.com Sun Feb 17 18:55:47 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 1U78So-0005X2-TL for gllmg-musl@plane.gmane.org; Sun, 17 Feb 2013 18:55:47 +0100 Original-Received: (qmail 29844 invoked by uid 550); 17 Feb 2013 17:55:25 -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 29831 invoked from network); 17 Feb 2013 17:55:25 -0000 Content-Disposition: inline In-Reply-To: <1360535421.23424.467.camel@eris.loria.fr> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:2806 Archived-At: On Sun, Feb 10, 2013 at 11:31:41PM +0100, Jens Gustedt wrote: > When switching optimization to higher levels (-O3) and enable link time > optimization (-flto) gcc finds two variables that might be clobbered > accross longjmp (orig_tail in dynlink) or vfork (f in popen): > > src/ldso/dynlink.c:1014:27: warning: variable ‘orig_tail’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered] > src/stdio/popen.c:21:8: warning: variable ‘f’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered] > > Trust the analysis of the compiler and protect these variables with > volatile. Both variables are only loaded once or twice, so this should > never cause a performance penalty. > > 1 1 src/ldso/dynlink.c > 1 1 src/stdio/popen.c > > diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c > index efbec8f..e19a21f 100644 > --- a/src/ldso/dynlink.c > +++ b/src/ldso/dynlink.c > @@ -1011,7 +1011,7 @@ void __init_ldso_ctors(void) > > void *dlopen(const char *file, int mode) > { > - struct dso *volatile p, *orig_tail, *next; > + struct dso *volatile p, *volatile orig_tail, *next; As far as I can tell, this is a false positive. orig_tail is never modified between setjmp and longjmp. Static analysis is probably failing due to subsequent modification to orig_tail after the last possible point at which a longjmp could occur. > diff --git a/src/stdio/popen.c b/src/stdio/popen.c > index ed20f5a..e5fbc4f 100644 > --- a/src/stdio/popen.c > +++ b/src/stdio/popen.c > @@ -18,7 +18,7 @@ FILE *popen(const char *cmd, const char *mode) > { > int p[2], op, i; > pid_t pid; > - FILE *f; > + FILE *volatile f; > sigset_t old; > const char *modes = "rw", *mi = strchr(modes, *mode); Could you explain what the issue is here? I'm not following it. I intend to remove the vfork usage soon anyway, but I'd like to understand (and commit a patch with a commit-message documenting what the problem was) if it's wrong right now for reasons other than the fact that vfork is wrong to begin with. But on the other hand, I don't want to commit a cargo-cult patch with a message like "because the compiler warnings said so"... Rich