From: Thomas Rast <trast@student.ethz.ch>
To: Jim Meyering <jim@meyering.net>
Cc: "Richard W.M. Jones" <rjones@redhat.com>,
Markus Trippelsdorf <markus@trippelsdorf.de>,
<git@vger.kernel.org>, "Shawn O. Pearce" <spearce@spearce.org>,
Jeff King <peff@peff.net>, Nicolas Pitre <nico@fluxnic.net>
Subject: Re: general protection faults with "git grep" version 1.7.7.1
Date: Tue, 25 Oct 2011 18:00:27 +0200 [thread overview]
Message-ID: <201110251800.28054.trast@student.ethz.ch> (raw)
In-Reply-To: <87y5w9ayoa.fsf@rho.meyering.net>
Jim Meyering wrote:
> Thomas Rast wrote:
> > [GCC moves access to a file-static variable across pthread_mutex_lock()]
>
> Thanks for the investigation.
> Actually, isn't gcc -O2's code-motion justified?
> While we *know* that those globals may be modified asynchronously,
> builtin/grep.c forgot to tell gcc about that.
I'm somewhat unwilling to believe that:
* "volatile" enforces three unrelated things, see e.g. [1].
* Removing "static" would do the same as it prevents the compiler from
proving at compile-time that pthread_mutex_lock() cannot affect the
variable in question.
If this is correct, it also means that all code in all pthreads
tutorials I can find works merely by the accident of not declaring
their variables "static".
Furthermore, a future smarter compiler with better link-time
optimization might again prove the same and eliminate the
"superfluous" load.
However, as a result of the discussion I now have a shorter testcase:
#include <pthread.h>
int y;
static int x;
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
void test ()
{
y = x;
pthread_mutex_lock(&m);
x = x + 1;
pthread_mutex_unlock(&m);
}
GCC 4.6.1 on F16 again assumes 'x' was not modified across the lock.
I also tested GCC 4.5.1 and 4.4.5, which instead issue a direct
add-to-memory instruction
addl $1, x(%rip)
in the locked part.
In the event that you and GCC 4.6.1 are right, I still vote for
removing 'static' instead of adding 'volatile' so as to allow basic
optimizations.
--
Thomas Rast
trast@{inf,student}.ethz.ch
next prev parent reply other threads:[~2011-10-25 16:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-24 20:11 general protection faults with "git grep" version 1.7.7.1 Markus Trippelsdorf
2011-10-24 21:49 ` Richard W.M. Jones
2011-10-24 22:58 ` Markus Trippelsdorf
2011-10-25 0:00 ` Bernt Hansen
2011-10-25 5:53 ` Jeff King
2011-10-25 11:11 ` Bernt Hansen
2011-10-25 13:50 ` Thomas Rast
2011-10-25 15:17 ` Jim Meyering
2011-10-25 15:32 ` Markus Trippelsdorf
2011-10-25 16:00 ` Thomas Rast [this message]
2011-10-25 16:07 ` Thomas Rast
2011-10-25 16:37 ` Jim Meyering
2011-10-25 16:54 ` Thomas Rast
2011-10-25 20:24 ` Jim Meyering
2011-10-25 15:37 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201110251800.28054.trast@student.ethz.ch \
--to=trast@student.ethz.ch \
--cc=git@vger.kernel.org \
--cc=jim@meyering.net \
--cc=markus@trippelsdorf.de \
--cc=nico@fluxnic.net \
--cc=peff@peff.net \
--cc=rjones@redhat.com \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).