This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/47460] New: Inconsistent behaviour of __sync_fetch_and_add builtin?
- From: "manuel dot holtgrewe at fu-berlin dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 25 Jan 2011 16:27:58 +0000
- Subject: [Bug tree-optimization/47460] New: Inconsistent behaviour of __sync_fetch_and_add builtin?
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47460
Summary: Inconsistent behaviour of __sync_fetch_and_add
builtin?
Product: gcc
Version: 4.4.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: manuel.holtgrewe@fu-berlin.de
I get the unexpected (for me) inconsistent behaviour of the
__sync_fetch_and_add builtin with the program below. My main confusion is
around the missing __sync_val_compare_and_swap_{1,2,4} when not explicitely
specifying the architecture in GCC 4.4.5, but availability in all other tried
variants.
Also, why is there a 64-bit variant when explicitely giving -march=i686 to g++
>=4.2 but missing one in g++-4.1?
Thanks!
Program gcc-atomic.cpp
--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<
template <typename T>
void test()
{
T volatile x = 0;
T y = 0;
T z = 0;
__sync_fetch_and_add(&x, y, z);
__sync_fetch_and_or(&x, y, z);
__sync_fetch_and_xor(&x, y, z);
__sync_val_compare_and_swap(&x, y, z);
}
int main()
{
test<char>();
test<unsigned char>();
test<int>();
test<unsigned int>();
test<short>();
test<unsigned short>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
return 0;
}
Output WITH -march=i686 switch
--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<
$ for i in 1 2 3 4 5; do g++-4.$i --version; g++-4.$i -dumpmachine; g++-4.$i
-march=i686 gcc-atomic.cpp; done
g++-4.1 (GCC) 4.1.3 20080704 (prerelease) (Debian 4.1.2-25)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
i486-linux-gnu
/tmp/cce8mfQl.o: In function `void test<long long>()':
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x46): undefined
reference to `__sync_fetch_and_add_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x5f): undefined
reference to `__sync_fetch_and_or_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x78): undefined
reference to `__sync_fetch_and_xor_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x9f): undefined
reference to `__sync_val_compare_and_swap_8'
/tmp/cce8mfQl.o: In function `void test<unsigned long long>()':
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x45):
undefined reference to `__sync_fetch_and_add_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x5e):
undefined reference to `__sync_fetch_and_or_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x77):
undefined reference to `__sync_fetch_and_xor_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x9e):
undefined reference to `__sync_val_compare_and_swap_8'
collect2: ld returned 1 exit status
g++-4.2 (GCC) 4.2.4 (Debian 4.2.4-6)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
i486-linux-gnu
g++-4.3 (Debian 4.3.2-1.1) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
i486-linux-gnu
g++-4.4.5 (GCC) 4.4.5
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
i686-pc-linux-gnu
g++-4.5.1 (GCC) 4.5.1
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
i686-pc-linux-gnu
Output WITHOUT -march=i686 switch
--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<
$ for i in 1 2 3 4 5; do g++-4.$i --version; g++-4.$i -dumpmachine; g++-4.$i
gcc-atomic.cpp; done
g++-4.1 (GCC) 4.1.3 20080704 (prerelease) (Debian 4.1.2-25)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
i486-linux-gnu
/tmp/ccGnLtMn.o: In function `void test<long long>()':
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x46): undefined
reference to `__sync_fetch_and_add_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x5f): undefined
reference to `__sync_fetch_and_or_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x78): undefined
reference to `__sync_fetch_and_xor_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x9f): undefined
reference to `__sync_val_compare_and_swap_8'
/tmp/ccGnLtMn.o: In function `void test<unsigned long long>()':
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x45):
undefined reference to `__sync_fetch_and_add_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x5e):
undefined reference to `__sync_fetch_and_or_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x77):
undefined reference to `__sync_fetch_and_xor_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x9e):
undefined reference to `__sync_val_compare_and_swap_8'
collect2: ld returned 1 exit status
g++-4.2 (GCC) 4.2.4 (Debian 4.2.4-6)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
i486-linux-gnu
/tmp/ccgFK94L.o: In function `void test<long long>()':
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x46): undefined
reference to `__sync_fetch_and_add_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x5f): undefined
reference to `__sync_fetch_and_or_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x78): undefined
reference to `__sync_fetch_and_xor_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x9f): undefined
reference to `__sync_val_compare_and_swap_8'
/tmp/ccgFK94L.o: In function `void test<unsigned long long>()':
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x45):
undefined reference to `__sync_fetch_and_add_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x5e):
undefined reference to `__sync_fetch_and_or_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x77):
undefined reference to `__sync_fetch_and_xor_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x9e):
undefined reference to `__sync_val_compare_and_swap_8'
collect2: ld returned 1 exit status
g++-4.3 (Debian 4.3.2-1.1) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
i486-linux-gnu
/tmp/ccM6VgC4.o: In function `void test<long long>()':
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x46): undefined
reference to `__sync_fetch_and_add_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x5f): undefined
reference to `__sync_fetch_and_or_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x78): undefined
reference to `__sync_fetch_and_xor_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x9f): undefined
reference to `__sync_val_compare_and_swap_8'
/tmp/ccM6VgC4.o: In function `void test<unsigned long long>()':
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x45):
undefined reference to `__sync_fetch_and_add_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x5e):
undefined reference to `__sync_fetch_and_or_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x77):
undefined reference to `__sync_fetch_and_xor_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x9e):
undefined reference to `__sync_val_compare_and_swap_8'
collect2: ld returned 1 exit status
g++-4.4.5 (GCC) 4.4.5
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
i686-pc-linux-gnu
/tmp/ccmEomIy.o: In function `void test<char>()':
gcc-atomic.cpp:(.text._Z4testIcEvv[void test<char>()]+0x56): undefined
reference to `__sync_val_compare_and_swap_1'
/tmp/ccmEomIy.o: In function `void test<unsigned char>()':
gcc-atomic.cpp:(.text._Z4testIhEvv[void test<unsigned char>()]+0x47): undefined
reference to `__sync_val_compare_and_swap_1'
/tmp/ccmEomIy.o: In function `void test<int>()':
gcc-atomic.cpp:(.text._Z4testIiEvv[void test<int>()]+0x4b): undefined reference
to `__sync_val_compare_and_swap_4'
/tmp/ccmEomIy.o: In function `void test<unsigned int>()':
gcc-atomic.cpp:(.text._Z4testIjEvv[void test<unsigned int>()]+0x4b): undefined
reference to `__sync_val_compare_and_swap_4'
/tmp/ccmEomIy.o: In function `void test<short>()':
gcc-atomic.cpp:(.text._Z4testIsEvv[void test<short>()]+0x5f): undefined
reference to `__sync_val_compare_and_swap_2'
/tmp/ccmEomIy.o: In function `void test<unsigned short>()':
gcc-atomic.cpp:(.text._Z4testItEvv[void test<unsigned short>()]+0x50):
undefined reference to `__sync_val_compare_and_swap_2'
/tmp/ccmEomIy.o: In function `void test<long>()':
gcc-atomic.cpp:(.text._Z4testIlEvv[void test<long>()]+0x4b): undefined
reference to `__sync_val_compare_and_swap_4'
/tmp/ccmEomIy.o: In function `void test<unsigned long>()':
gcc-atomic.cpp:(.text._Z4testImEvv[void test<unsigned long>()]+0x4b): undefined
reference to `__sync_val_compare_and_swap_4'
/tmp/ccmEomIy.o: In function `void test<long long>()':
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x46): undefined
reference to `__sync_fetch_and_add_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x5f): undefined
reference to `__sync_fetch_and_or_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x78): undefined
reference to `__sync_fetch_and_xor_8'
gcc-atomic.cpp:(.text._Z4testIxEvv[void test<long long>()]+0x9f): undefined
reference to `__sync_val_compare_and_swap_8'
/tmp/ccmEomIy.o: In function `void test<unsigned long long>()':
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x45):
undefined reference to `__sync_fetch_and_add_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x5e):
undefined reference to `__sync_fetch_and_or_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x77):
undefined reference to `__sync_fetch_and_xor_8'
gcc-atomic.cpp:(.text._Z4testIyEvv[void test<unsigned long long>()]+0x9e):
undefined reference to `__sync_val_compare_and_swap_8'
collect2: ld returned 1 exit status
g++-4.5.1 (GCC) 4.5.1
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
i686-pc-linux-gnu