Bug 51332 - __sync_add_and_fetch segfaults when -fPIC is enabled
Summary: __sync_add_and_fetch segfaults when -fPIC is enabled
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.2
: P3 major
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-28 11:52 UTC by Luca Martini
Modified: 2011-11-28 12:06 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
preprocessor output (3.63 KB, text/plain)
2011-11-28 11:52 UTC, Luca Martini
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Luca Martini 2011-11-28 11:52:44 UTC
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
Comment 1 Jonathan Wakely 2011-11-28 12:06:34 UTC
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.