Bug 56296

Summary: Undefined reference to __sync_add_and_fetch_8 for int64_t on MIPS32.
Product: gcc Reporter: Balazs Kilvady <kilvadyb>
Component: libgccAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal CC: jakub
Priority: P3    
Version: unknown   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Balazs Kilvady 2013-02-12 11:41:43 UTC
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)
Comment 1 Jakub Jelinek 2013-02-12 11:56:39 UTC
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).
Comment 2 Balazs Kilvady 2013-02-12 12:12:22 UTC
(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.
Comment 3 Andrew Pinski 2013-02-12 18:21:34 UTC
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.