[LLVMbugs] [Bug 23262] New: undefined reference to `__atomic_load_8', when it comes to 64-bit atomic load.
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Apr 16 21:20:21 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=23262
Bug ID: 23262
Summary: undefined reference to `__atomic_load_8', when it
comes to 64-bit atomic load.
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: rwindz0 at gmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
clang fails to deal with 64-bit atomic load and compare_exchange_weak when it
comes with -stdlib=libstdc++, while gcc can deal with it correctly.
The test program is from
http://preshing.com/20150402/you-can-do-any-kind-of-atomic-read-modify-write-operation/
:
cat >test-atomic.cc<<EOF
#include <atomic>
struct Terms
{
uint32_t x;
uint32_t y;
};
std::atomic<Terms> terms;
void atomicFibonacciStep()
{
Terms oldTerms = terms.load();
Terms newTerms;
do
{
newTerms.x = oldTerms.y;
newTerms.y = oldTerms.x + oldTerms.y;
}
while (!terms.compare_exchange_weak(oldTerms, newTerms));
}
int main() {
atomicFibonacciStep();
}
EOF
test with:
$clang++-3.7 -std=c++11 -stdlib=libstdc++ -O3 test-atomic.cc
/tmp/test-atomic-190571.o: In function
`std::atomic<Terms>::load(std::memory_order) const':
test-atomic.cc:(.text[_ZNKSt6atomicI5TermsE4loadESt12memory_order]+0x14):
undefined reference to `__atomic_load_8'
/tmp/test-atomic-190571.o: In function
`std::atomic<Terms>::compare_exchange_weak(Terms&, Terms, std::memory_order,
std::memory_order)':
test-atomic.cc:(.text[_ZNSt6atomicI5TermsE21compare_exchange_weakERS0_S0_St12memory_orderS3_]+0x2b):
undefined reference to `__atomic_compare_exchange_8'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$g++-4.9 -std=c++11 -O3 test-atomic.cc
(exited status 0)
$clang++-3.7 -std=c++11 -stdlib=libstdc++ -O3 -S test-atomic.cc -o -
...
callq __atomic_load_8
movq %rax, 8(%rsp)
movq %rax, %rcx
shrq $32, %rcx
movl %ecx, %edx
addl %eax, %edx
shlq $32, %rdx
orq %rcx, %rdx
leaq 8(%rsp), %rsi
movl $terms, %edi
movl $5, %ecx
movl $5, %r8d
callq __atomic_compare_exchange_8
testb %al, %al
jne .LBB0_3
...
$g++-4.9 -std=c++11 -O3 -S test-atomic.cc -o -
...
.LFB329:
.cfi_startproc
movq terms(%rip), %rax
movq %rax, %rdx
movl %eax, -24(%rsp)
shrq $32, %rdx
movl %edx, -20(%rsp)
.p2align 4,,10
.p2align 3
.L4:
addl %edx, %eax
movl %edx, %edx
salq $32, %rax
orq %rax, %rdx
movq -24(%rsp), %rax
lock cmpxchgq %rdx, terms(%rip)
jne .L6
rep ret
.p2align 4,,10
.p2align 3
...
BTW: clang++ works just fine with libc++. (the generated assembly code looks
almost the same to gcc's)
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150417/ddacc844/attachment.html>
More information about the llvm-bugs
mailing list