I use GCC 4.7.2 on Debian and get linker errors whenever I try to use <atomic> objects with 16 byte values. I am running VMware x86_64, which can support the CMPXCHG16B instruction, but even if I did not have the necessary hardware, I donβt understand why a linker error should be generated here. As far as I know, the <atomic> library should return to using regular locks if the hardware does not support the necessary CAS operation.
Anyway, here is a very simple test case to reproduce this problem:
#include <atomic> #include <cstdint> struct foo { std::uint64_t x; std::uint64_t y; }; int main() { std::atomic<foo> f1({0,0}); foo f2 = {0,0}; foo f3 = {1,1}; f1.compare_exchange_strong(f2, f3); }
When I compile this, I get:
# g++ test.cpp -o test -std=c++11 -g3 /tmp/ccziKZis.o: In function `std::atomic<foo>::compare_exchange_strong(foo&, foo, std::memory_order, std::memory_order)': /usr/include/c++/4.7/atomic:259: undefined reference to `__atomic_compare_exchange_16' collect2: error: ld returned 1 exit status
Please note that if I change the program so that foo only 8 bytes, I do not get a linker error. What's going on here?
Siler source share