This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: basic asm and memory clobbers
- From: David Wohlferd <dw at LimeGreenSocks dot com>
- To: Andrew Haley <aph at redhat dot com>, Richard Henderson <rth at redhat dot com>, Jakub Jelinek <jakub at redhat dot com>
- Cc: Segher Boessenkool <segher at kernel dot crashing dot org>, Jeff Law <law at redhat dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, rth at gcc dot gnu dot org, pinskia at gcc dot gnu dot org, Sandra Loosemore <sandra at codesourcery dot com>
- Date: Mon, 23 Nov 2015 13:02:55 -0800
- Subject: Re: basic asm and memory clobbers
- Authentication-results: sourceware.org; auth=none
- References: <564AC155 dot 4040601 at LimeGreenSocks dot com> <564B9CB1 dot 1060001 at redhat dot com> <564E762B dot 6070705 at LimeGreenSocks dot com> <564EF338 dot 4030703 at redhat dot com> <564EF7FF dot 1070107 at LimeGreenSocks dot com> <564F008B dot 8040703 at redhat dot com> <564F1436 dot 2060005 at LimeGreenSocks dot com> <564F1A7D dot 9050607 at redhat dot com> <20151120152039 dot GA15922 at gate dot crashing dot org> <564F3C6E dot 5010908 at redhat dot com> <20151120153431 dot GJ5675 at tucnak dot redhat dot com> <564F46CF dot 2030403 at redhat dot com> <564FB2ED dot 70803 at LimeGreenSocks dot com> <56506A03 dot 7030609 at LimeGreenSocks dot com> <5652E4A6 dot 9090905 at redhat dot com>
On 11/23/2015 2:04 AM, Andrew Haley wrote:
On 21/11/15 12:56, David Wohlferd wrote:
So, what now?
While I'd like to take the big step and start kicking out warnings for
non-top-level right now, that may be too bold for phase 3. A more
modest step for v6 would just provide a way to find them (maybe
something like -Wnon-top-basic-asm or -Wonly-top-basic-asm) and doc the
current behavior as well as the upcoming change.
Warnings would be good.
Richard's suggestion was:
> I'm suggesting that we don't accept [basic asm] at all inside a
function. One must audit the source and make a conscious decision to
write asm("bla" : ); instead. Accepting basic asm outside of a function
is perfectly ok.
I'm really not a compiler-writer, but I've taken a shot at implementing
this. While Richard is talking about completely deprecating this
feature (a direction I support), I've started by emitting warnings, and
by having the warnings disabled by default. This allows people to
experiment with the new direction without getting clobbered by it. My
intent is something like this:
-Wonly-top-basic-asm
Warn if basic @code{asm} statements are used inside a function (ie not
at file scope/top level). Due to the potential for unsafe optimizations,
always use extended instead of basic asm inside functions. This
warning is disabled by default and is not enabled by -Wall or -Wextra.
I probably won't include the bits about Wall or Wextra in the actual doc
patch. They're here more to provoke comments in case someone thinks
this behavior should change. I'm open to suggestions about alternate
names, too.
I've got this working for both c and c++. It doesn't affect other
places that use "asm" like "explicit register variables," "asm labels,"
"extended asm" or "top level basic asm." It is also pleasantly small.
As written, it should be useful to find places in current code that are
at risk.
However (there's always a 'however'), it doesn't correctly handle
"naked" functions (ie __attribute__((naked)) ). By definition, naked
functions can *only* include basic asm
(https://gcc.gnu.org/ml/gcc/2014-05/msg00172.html). So generating a
warning for them is incorrect.
I'll need help fixing that.
I don't know if it is possible from within the parsers (where my current
code is being added) to walk back up and get the attributes for the
function. I assume not. In that case, I'll need some help finding some
place up the call stack where you can. Suggestions welcome.
The patch is at http://www.LimeGreenSocks.com/gcc/24414f.zip and
includes test code.
My warning still holds: there are modes of compilation on some
machines where you can't clobber all registers without causing reload
failures. This is why Jeff didn't fix this in 1999. So, if we really
do want to clobber "all" registers in basic asm it'll take a lot of
work.
I was always reluctant to see this change made. In addition to the
issues you mention, I had questions about the impact on the surrounding
code. I like Richard's direction much better. We can start with a
disabled warning, then upgrade as seems warranted.
dw