asm problem with and without -fPIC on x86

Tim Blechmann tim@klingt.org
Thu Mar 29 09:39:00 GMT 2007


hi all,

i've got the following problem:
i am using the atomic_ops library to use the cmpxchg8b opcode. the
specific section for x86 machines looks like this:

  __asm__ __volatile__("lock; cmpxchg8b %0; setz %1"
                   : "=m"(*addr), "=q"(result)
                   : "m"(*addr), "d" (old_val1), "a" (old_val2),
                     "c" (new_val1), "b" (new_val2) : "memory");

unfortunately, this doesn't compile, when building as a shared library
with the -fPIC flag, as the `b` register can't be used.
so i wrote a workaround:

  __asm__ __volatile__("push %%ebx; movl %6,%%ebx; lock; cmpxchg8b %0; setz %1; pop %%ebx"
                   : "=m"(*addr), "=q"(result)
                   : "m"(*addr), "d" (old_val1), "a" (old_val2),
                     "c" (new_val1), "m" (new_val2) : "memory");

this piece of code works fine if the -fPIC flag is enabled. but when
compiling this without -fPIC and switching on optimization (-O), the
code compiles, but doesn't work correctly anymore. without optimization
it works fine, though.

is this a compiler bug or a user bug?

thanks in advance, tim

--
tim@klingt.org    ICQ: 96771783
http://tim.klingt.org

Nothing exists until or unless it is observed. An artist is making
something exist by observing it. And his hope for other people is that
they will also make it exist by observing it. I call it 'creative
observation.' Creative viewing.
  William S. Burroughs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20070329/5ff91b03/attachment.sig>


More information about the Gcc-help mailing list