Bug 114004 - gcc -O2 -mcpu=i686 can produce wrong code
gcc -O2 -mcpu=i686 can produce wrong code
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: gcc (Show other bugs)
3.0
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-01-21 05:51 EST by Pancrazio `ezio' de Mauro
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-01-21 06:09:31 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Sample C code that does not produce correct results when compiled with -O2 -mcpu=i686 (3.50 KB, text/plain)
2004-01-21 05:52 EST, Pancrazio `ezio' de Mauro
no flags Details

  None (edit)
Description Pancrazio `ezio' de Mauro 2004-01-21 05:51:07 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5)
Gecko/20031007 Firebird/0.7 StumbleUpon/1.89

Description of problem:
gcc seems to produce incorrect i686-optimised code at times, see
attached sample code.

Version-Release number of selected component (if applicable):
gcc-3.2.3-24

How reproducible:
Always

Steps to Reproduce:
1. gcc -c -o udp_checksum_i386_o2.o -O2 -I/usr/src/linux-2.4/include
udp_checksum.c
2. gcc -c -o udp_checksum_i686_o2.o -mcpu=i686 -O2
-I/usr/src/linux-2.4/include udp_checksum.c
3. gcc -c -o udp_checksum_i686.o -mcpu=i686
-I/usr/src/linux-2.4/include udp_checksum.c
4. insmod ./udp_checksum_i386_o2.o (warning! this will taint the kernel)
5. for each incoming UDP datagram watch /var/log/messages for lines like:
kernel: New src: 0xXXXXXXXX; Old src: 0xXXXXXXXX
kernel: computed checksum: 0xe520;  packet checksum: 0xe520
6. rmmod udp_checksum_i386_o2
7. insmod udp_checksum_i686.o (kernel is already tainted at this stage...)
8. for each incoming UDP datagram watch /var/log/messages for lines like:
kernel: New src: 0xXXXXXXXX; Old src: 0xXXXXXXXX
kernel: computed checksum: 0xd39e;  packet checksum: 0xd39e
9. rmmod udp_checksum_i686
10. insmod ./udp_checksum_i686_o2.o
11. for each incoming UDP datagram watch /var/log/messages for lines like:
kernel: New src: 0xXXXXXXXX; Old src: 0xXXXXXXXX
kernel: computed checksum: 0x9fb3;  packet checksum: 0xa75e
kernel: New src: 0xXXXXXXXX; Old src: 0xXXXXXXXX
kernel: computed checksum: 0xc3f5;  packet checksum: 0xcba0
kernel: New src: 0xXXXXXXXX; Old src: 0xXXXXXXXX
kernel: computed checksum: 0x75b3;  packet checksum: 0x7d5e

Actual Results:  The computed checksums, when the module is compiled
with -O2 -mcpu=i686, are consistently wrong

Expected Results:  The computed checksums should always match, with or
without -O2, with ot without -mcpu=i686

Additional info:
Comment 1 Pancrazio `ezio' de Mauro 2004-01-21 05:52:29 EST
Created attachment 97143 [details]
Sample C code that does not produce correct results when compiled with -O2 -mcpu=i686
Comment 2 Jakub Jelinek 2004-01-21 05:56:08 EST
Kernel code is not strict aliasing safe, so you must use -fno-strict-aliasing
for all kernel code.
Do you see any problems if you recompile with -fno-strict-aliasing?
Comment 3 Pancrazio `ezio' de Mauro 2004-01-21 06:07:10 EST
It works perfectly with -fno-strict-aliasing, thank you very much for
your quick reply!

Note You need to log in before you can comment on or make changes to this bug.