compiling inc.c: #include <inttypes.h> int main() { int64_t var = 7; __sync_add_and_fetch(&var, 1); return 0; } Output: (squeeze)/data/kilvadyb/webkit-mips$ mipsel-linux-gnu-gcc -Wall -o i inc.c /tmp/ccGwTrIE.o: In function `main': inc.c:(.text+0x3c): undefined reference to `__sync_add_and_fetch_8' collect2: ld returned 1 exit status Compiler version: Using built-in specs. Target: mipsel-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/mipsel-linux-gnu/include/c++/4.4.5 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --disable-libssp --enable-checking=release --program-prefix=mipsel-linux-gnu- --includedir=/usr/mipsel-linux-gnu/include --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=mipsel-linux-gnu --with-headers=/usr/mipsel-linux-gnu/include --with-libs=/usr/mipsel-linux-gnu/lib Thread model: posix gcc version 4.4.5 (Debian 4.4.5-8)
Why do you think this is a bug? If a target doesn't support atomic operations on certain variable sizes, this is what you get, you are out of luck with atomicity in that case. In GCC 4.8 you can use libatomic which will provide emulation for that case using locks (though, of course, in that case all accesses to the var need to be done using atomic builtins).
(In reply to comment #1) > Why do you think this is a bug? If a target doesn't support atomic operations > on certain variable sizes, this is what you get, you are out of luck with > atomicity in that case. In GCC 4.8 you can use libatomic which will provide > emulation for that case using locks (though, of course, in that case all > accesses to the var need to be done using atomic builtins). Thank you for the quick reply.
To get 64bit __sync_add_and_fetch on MIPS, you need to use either n32, n64 or o64 ABIs or manually use the 64bit instructions if you know you are only to run on some 64bit processors.