[hjl@gnu-9 gcc]$ cat /tmp/x.c #include <stdio.h> #ifdef OLD extern int __sync_bool_compare_and_swap_di (long *, long, long); #else #define __sync_bool_compare_and_swap_di __sync_bool_compare_and_swap #endif int foo (long *x) { long address = *x; if (!__sync_bool_compare_and_swap_di (x, address, (address | 1))) return 0; else return 1; } int main () { long val = 0; int ret; printf ("val: 0x%lx\n", val); ret = foo (&val); printf ("ret: %d: val: 0x%lx\n", ret, val); return; } [hjl@gnu-9 gcc]$ ./xgcc -B./ -O2 /tmp/x.c [hjl@gnu-9 gcc]$ ./a.out val: 0x0 ret: 1: val: 0x1 [hjl@gnu-9 gcc]$ ./xgcc -B./ -O2 /tmp/x.c -m32 /tmp/ccQy8ACO.o: In function `foo': x.c:(.text+0x1c): undefined reference to `__sync_bool_compare_and_swap_4' collect2: ld returned 1 exit status
When, exactly, did you think that cmpxchg was added? Use -march=i486. Duh.
But there is no __sync_bool_compare_and_swap_4 in source code. If it isn't available, shouldn't gcc leave __sync_bool_compare_and_swap alone.
No, because __sync_bool_compare_and_swap is overloaded. This expansion to __sync_bool_compare_and_swap_N is documented.