http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51332

             Bug #: 51332
           Summary: __sync_add_and_fetch segfaults when -fPIC is enabled
    Classification: Unclassified
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: luca.mart...@tin.it


Created attachment 25931
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25931
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

Reply via email to