Created attachment 25931 [details] preprocessor output The code generated from compiler intrinsic __sync_add_and_fetch (on a 64bit value) is erroneous when the -fPIC switch is enabled. It seems that when the -fPIC switch is enabled, instruction CMPXCHG8B references register EBX as a base pointer for the memory operand, whereas EBX must contain part of the value to be incremented. See a minimal reproducible example in attachment. We experienced the problem when compiling with the following flags: gcc version 4.1.2 20080704 (Red Hat 4.1.2-51) /usr/libexec/gcc/x86_64-redhat-linux/4.1.2/cc1 -E -quiet -v main.c -m32 -march=i686 -fPIC -fworking-directory -fpch-preprocess -o main.i the generated instruction is lock cmpxchg8b (%ebx) and should have been lock cmpxchg8b (%esi) we could not reproduce the bug with the gcc 4.4.4
4.1.2 is no longer supported and no bugs in that version will ever get fixed now. You've already stated there's no problem with a current release. If you got the compiler from Red Hat and want it fixed then report it to them.