Bug 114004

Summary: gcc -O2 -mcpu=i686 can produce wrong code
Product: Red Hat Enterprise Linux 3 Reporter: Pancrazio `ezio' de Mauro <pdemauro>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 3.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-01-21 11:09:31 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Sample C code that does not produce correct results when compiled with -O2 -mcpu=i686 none

Description Pancrazio `ezio' de Mauro 2004-01-21 10:51:07 UTC
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 10:52:29 UTC
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 10:56:08 UTC
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 11:07:10 UTC
It works perfectly with -fno-strict-aliasing, thank you very much for
your quick reply!