Re: Compiler optimizing variables in inline assembly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/27/2014 01:18 PM, Cody Rigney wrote:
>> On Fri, Feb 21, 2014 at 10:02 AM, Andrew Haley <aph@xxxxxxxxxx> wrote:
>>> It's hard for me to give a 100% answer to that one, but GCC has an
>>> idea what memory is reachable from every pointer.  So, this won't
>>> clobber memory that's unreachable or has a different type from that
>>> pointer.  It probably doesn't matter.
>>>
> 
> Doing "=m" (*a) in the output operand worked! And so did "memory" to
> the clobber list. Thanks!

I have been informed that this is wrong, sorry.

The correct way to do it is like so:

---------------------------------------
If you know how large the accessed memory is, you can add it as input or
output but if this is not known, you should add `memory'.  As an example,
if you access ten bytes of a string, you can use a memory input like:

     {"m"( ({ struct { char x[10]; } *p = (void *)ptr ; *p; }) )}.

---------------------------------------

If you use a zero-length array in the struct (i.e. char x[0]) that will
effectively do the job if you don't know how large the array is, but there
seems to be some doubt whether this is guaranteed.  A memory clobber really
is guaranteed, but seems a bit like overkill.

Andrew.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux