This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: asm problem with and without -fPIC on x86
- From: Andrew Haley <aph at redhat dot com>
- To: Tim Blechmann <tim at klingt dot org>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 29 Mar 2007 10:47:01 +0100
- Subject: Re: asm problem with and without -fPIC on x86
- References: <1175158653.9488.57.camel@localhost>
Tim Blechmann writes:
> 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?
You know, this would have been *so* much easier to figure out it you'd
provided a test case.
Andrew.
--
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903