On 25 April 2017 at 10:16, Nikunj A Dadhania <nik...@linux.vnet.ibm.com> wrote:
> Peter Maydell <peter.mayd...@linaro.org> writes:
>
>> On 25 April 2017 at 09:58, Nikunj A Dadhania <nik...@linux.vnet.ibm.com> 
>> wrote:
>>>     /tmp/atomic-1660e0.o: In function `main':
>>>     /tmp/atomic.c:(.text+0x28): undefined reference to `__atomic_load_8'
>>>     /tmp/atomic.c:(.text+0x40): undefined reference to `__atomic_store_8'
>>>     /tmp/atomic.c:(.text+0x69): undefined reference to 
>>> `__atomic_compare_exchange_8'
>>>     /tmp/atomic.c:(.text+0x7d): undefined reference to `__atomic_exchange_8'
>>>     /tmp/atomic.c:(.text+0x91): undefined reference to 
>>> `__atomic_fetch_add_8'
>>>     clang-3.9: error: linker command failed with exit code 1 (use -v to see 
>>> invocation)
>>>
>>> With -latomic, the linker succeeds in getting the binary.
>>
>> What host is this on ?
>
> $ uname -a
> Linux abhimanyu 4.9.13-200.fc25.x86_64 #1 SMP Mon Feb 27 16:48:42 UTC 2017 
> x86_64 x86_64 x86_64 GNU/Linux

Hmm, I can repro that, but there's a problem even if we do link against
libatomic. If you disassemble the resulting binaries, gcc produces
what we want:
 f0 48 01 45 e8          lock add %rax,-0x18(%rbp)
and other inline atomic instructions.
clang on the other hand produces
 e8 33 fe ff ff          callq  400610 <__atomic_fetch_add_8@plt>
which is an expensive call to an out of line subroutine.

We need to figure out how to get clang to just emit the inline
operations.

thanks
-- PMM

Reply via email to