This is the mail archive of the
mailing list for the GCC project.
Re: basic asm and memory clobbers - Proposed solution
- From: David Wohlferd <dw at LimeGreenSocks dot com>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: Andrew Haley <aph at redhat dot com>, Jeff Law <law at redhat dot com>, rth at redhat dot com, Richard Earnshaw <Richard dot Earnshaw at foss dot arm dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, Paul_Koning at Dell dot com, jakub at redhat dot com, rth at gcc dot gnu dot org, pinskia at gcc dot gnu dot org, Segher Boessenkool <segher at kernel dot crashing dot org>, Ian Lance Taylor <iant at google dot com>, Sandra Loosemore <sandra at codesourcery dot com>, Hans-Peter Nilsson <hp at bitrange dot com>, bernd dot edlinger at hotmail dot de
- Date: Wed, 16 Dec 2015 17:41:04 -0800
- Subject: Re: basic asm and memory clobbers - Proposed solution
- Authentication-results: sourceware.org; auth=none
- References: <56552209 dot 1020306 at LimeGreenSocks dot com> <56592801 dot 9010606 at LimeGreenSocks dot com> <565DC5F4 dot 6080804 at foss dot arm dot com> <565E1E37 dot 9080609 at LimeGreenSocks dot com> <alpine dot DEB dot 2 dot 10 dot 1512012323160 dot 12604 at digraph dot polyomino dot org dot uk> <565E6862 dot 7070401 at redhat dot com> <566B4BA1 dot 8000509 at LimeGreenSocks dot com> <566BEE35 dot 6070804 at redhat dot com> <566D0CE6 dot 6090905 at LimeGreenSocks dot com> <566E9191 dot 9030106 at redhat dot com> <567092B9 dot 6020703 at LimeGreenSocks dot com> <alpine dot DEB dot 2 dot 10 dot 1512152238290 dot 10678 at digraph dot polyomino dot org dot uk>
On 12/15/2015 2:43 PM, Joseph Myers wrote:
On Tue, 15 Dec 2015, David Wohlferd wrote:
Unlike top level, using basic asm within a function is deprecated. No new code
should use this feature, but should use extended asm instead. Existing code
should begin replacing such usage. Instances of affected code can be found
using -Wonly-top-basic-asm. For help making this conversion, see "How to
convert Basic asm to Extended asm."
I think the typical use of basic asm is: you want to manipulate I/O
registers or other such state unknown to the compiler (not any registers
the compiler might use itself), and you want to do it in a way that is
maximally compatible with as many compilers as possible (hence limiting
yourself to the syntax subset that's in the C++ standard, for example).
Compatibility with a wide range of other compilers is the critical thing
here; this is not a GCC-invented feature, and considerations for
deprecating an externally defined feature are completely different from
considerations for GCC-invented features.
Do you have evidence that it is
now unusual for compilers to support basic asm without supporting
GCC-compatible extended asm, or that other compiler providers generally
consider basic asm deprecated?
On the contrary, I would be surprised to learn that there are ANY
compilers (other than clang) that support gcc's extended asm format.
And although there is no standard that seems to require it, I'm not
certainly not prepared to say that basic asm is "generally deprecated."
But the fact that there is no standard may make "doing what other
compilers do" challenging.
For example quoting from Bernd's email regarding the windriver diab
compiler: "non-scratch registers must be preserved." Implying that
scratch registers (which they apparently only list for ARM) are
That seems like a sensible approach (and avoids the frame pointer
problem). But I'm not prepared to extrapolate from that how all
compilers do or should handle basic asm. However it does mean that the
suggestion being proposed here to have basic asm only clobber memory
would not be compatible with windriver's approach to basic asm. And
Jeff's proposal for gcc to clobber "all registers" wouldn't be
compatible with them either.
I agree that "oh, surprise! gcc does this differently than compiler X!"
is a bad thing. But without standards, trying to be compatible with how
"everyone else" does it may not be practical. You'll note that
windriver made no particular effort to be compatible with gcc. And of
course any change will make gcc v7 work differently than gcc v4, v5, v6.
If compatibility with other compilers is an important criteria when
determining how gcc should handle basic asm, someone's going to need to
do some research and some prioritizing.
In the meantime, raising awareness of this issue via docs and warnings
seems a low-cost way to start.