https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65756
Bug ID: 65756 Summary: undefined reference to __atomic_store for odd-sized std::atomic<T> Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org The following C++ 11 program fails to link with GCC (both 4.9 and 5.0) because the primary std::atomic template allocates 3 bytes for both a and aa and calls __atomic_store(&aa.a, &tmp, __ATOMIC_SEQ_CST). GCC only supports calls to __atomic_store with power of 2 arguments of at most 8. Assuming the code is well-defined (I couldn't find anything to suggest otherwise -- the type meets the trivially-copyable requirement) it seems that specializations of the template on types of such sizes should add padding up to the nearest greater power of 2 and increase their own alignment so as to make it possible to manipulate them atomically. Larger specializations will need to make use of a mutex. $ cat a.cpp && g++ -Wall -Wpedantic -std=c++11 a.cpp #include <atomic> int main (void) { struct A { char a [3]; } a = { { 'a', 'b', 'c' } }; std::atomic<A> aa; aa.store (a); } /tmp/ccGQyZte.o: In function `std::atomic<main::A>::store(main::A, std::memory_order)': a.cpp:(.text+0xf0): undefined reference to `__atomic_store' collect2: error: ld returned 1 exit status