Bug #20803 ICC 9.1.039 produces bad code compiling "mysql_client_test.c"
Submitted: 1 Jul 2006 0:36 Modified: 30 Oct 2007 0:30
Reporter: Kent Boortz Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S2 (Serious)
Version:5.0.23-pre OS:Linux (IA64)
Assigned to: Kent Boortz CPU Architecture:Any
Tags: icc

[1 Jul 2006 0:36] Kent Boortz
Description:
The test 'test_basic_cursors' inside "mysql_client_test.c" gives
a segmentation fault, if compiled with icc and -O2 or above. You
can test this with (in a built source tree)

 % cd mysql-test
 % ./mysql-test-run.pl --start-and-exit mysql_client_test
 % ../tests/mysql_client_test --no-defaults --testcase --user=root \ 
   --port=9306 --socket=var/tmp/master.sock test_basic_cursors

Inlining migh not be the reason, but a -fno-inline makes the code
work again. Examining in gdb shows that the execution stops in
function stmt_fetch_fetch_row() and the head of the "for" loop.
Unfortunately optimization and "-g" doesn't work well, and I could
not get any real information on what is going on.

How to repeat:
Compile the 5.0.23 sources with icc 9.1.039, and configure like

 CC=icc
 CXX=icpc
 CFLAGS="-O3 -unroll2 -ip -mp -restrict"
 CXXFLAGS="-O3 -unroll2 -ip -mp -restrict"
 LDFLAGS="-static-libgcc -static-libcxa -i-static"
 export CC CXX CFLAGS CXXFLAGS LDFLAGS

 ./configure --disable-shared \  
 --without-embedded-server --with-innodb \ 
 --with-archive-storage-engine --without-bench \ 
 --with-zlib-dir=bundled --with-big-tables \ 
 --enable-assembler --enable-local-infile \ 
 --with-mysqld-user=mysql --with-pic --prefix=/ \ 
 --with-extra-charsets=complex \ 
 --enable-thread-safe-client --with-readline

 make

 cd mysql-test
 ./mysql-test-run.pl mysql_client_test
[1 Aug 2006 18:28] Joerg Bruehe
Until proof of the contrary, I assume that this failure is related:

=====
mysql_client_test              [ fail ]

Errors are (from /PATH/mysqltest-time) :
mysqltest: At line NNN: command "$MYSQL_CLIENT_TEST --getopt-ll-test=25600M" failed
(the last lines may be the most important ones)
=====

Occurred in the 5.0.24 release build in these tests:
Do-rpm-rhas4-ia64-5.0-pro-gpl.rhel4.log   normal
Do-rpm-rhas4-ia64-5.0-pro.rhel4.log   normal
Do-rpm-rhas4-ia64-5.0-standard.rhel4.log   normal
Do-rpm-rx2620b-5.0-pro-gpl.rhel3.log   normal
Do-rpm-rx2620b-5.0-pro.rhel3.log   normal
Do-rpm-rx2620b-5.0-standard.rhel3.log   normal
Do-rpm-sles9-ia64-5.0-pro-gpl.sles9.log   normal
Do-rpm-sles9-ia64-5.0-pro.sles9.log   normal
Do-rpm-sles9-ia64-5.0-standard.sles9.log   normal
rx2620b-icc-glibc23-5.0-cluster.log   normal
rx2620b-icc-glibc23-5.0-cluster.log   ps
rx2620b-icc-glibc23-5.0-cluster.log   NDB
rx2620b-icc-glibc23-5.0-max.log   normal
rx2620b-icc-glibc23-5.0-max.log   ps
rx2620b-icc-glibc23-5.0-max.log   NDB
rx2620b-icc-glibc23-5.0-pro.log   normal
rx2620b-icc-glibc23-5.0-pro.log   ps
rx2620b-icc-glibc23-5.0-standard.log   normal
rx2620b-icc-glibc23-5.0-standard.log   ps
rx2620b-icc-glibc23-5.0-pro-gpl.log   normal
rx2620b-icc-glibc23-5.0-pro-gpl.log   ps

All the above are platforms with the IA64 CPU, where we use the Intel "icc" compiler.
The test *passed* on "production", where we use "icc" on a "x86" CPU.
[3 Dec 2006 19:27] Kent Boortz
Reverified with icc 9.1.0.45 and MySQL 5.0.30,
the problem is still there.
[16 Apr 2007 18:45] Magnus Blåudd
Small test file for icc on IA-64

Attachment: bug20803.c (text/x-csrc), 1.57 KiB.

[16 Apr 2007 18:46] Magnus Blåudd
Uploaded small C program that will cause segfault when compiled as "icc file.c && ./a.out" with:

$ gcc -V
Intel(R) C Itanium(R) Compiler for Itanium(R)-based applications
Version 9.1    Build 20061105 Package ID: l_cc_c_9.1.045
Copyright (C) 1985-2006 Intel Corporation.  All rights reserved.
$ cat /proc/cpuinfo
processor  : 0
vendor     : GenuineIntel
arch       : IA-64
family     : Itanium 2
model      : 2
revision   : 2
archrev    : 0
features   : branchlong
cpu number : 0
cpu regs   : 4
cpu MHz    : 1299.969209
itc MHz    : 1299.969209
BogoMIPS   : 1946.15

processor  : 1
vendor     : GenuineIntel
arch       : IA-64
family     : Itanium 2
model      : 2
revision   : 2
archrev    : 0
features   : branchlong
cpu number : 0
cpu regs   : 4
cpu MHz    : 1299.969209
itc MHz    : 1299.969209
BogoMIPS   : 1946.15

$ uname -a
Linux rx2620b.mysql.com 2.4.21-37.EL #1 SMP Wed Sep 7 13:24:42 EDT 2005 ia64 ia64 ia64 GNU/Linu
[27 Apr 2007 12:18] Heinz Bast
Bug has been reported and escalated to Intel Itanium Compiler Engineering. Issue number Intel Premier Support: Q430699

The cause has been identified as an incorrect machine instruction being generated in the context of software pre-fetching after a subroutine got in-lined.

As a workaround, the bug can be avoided by disabling in-lining ( -ip--no-inlining) or lowering optimziation to O1 or less ( default is -O2)

I will update the case as soon as a compiler with a bug fix will be available
[1 Jun 2007 11:14] Heinz Bast
The issue has been fixed by Intel Compiler engineering. It is triggered by pre-fetching data in the context of procedure in-lining. The fix will be available in the next update of the 9.1 and 10.0 release.

The recommended workaround until availability of the fix: Add option -prefetch- to the compilation to prevent pre-fetching. Pre-fetching doesn't help very much on a code like MySQL DB thus the performance impact should be minimal to invisble. 

Heinz
[20 Jul 2007 10:49] Heinz Bast
Intel Compiler 10.025 has a fix for the issue; ran test case and verified fix on 2007-07-23
[28 Oct 2007 16:34] Kent Boortz
This problem was solved by upgrading to icc 10.0.026,
was used in MySQL server version 5.0.44sp1, and will be
used in upcoming 5.0.50 and 5.1.23.
[30 Oct 2007 0:30] Paul DuBois
Noted in 5.0.50, 5.1.23 changelogs.

Worked around an icc problem with an incorrect machine instruction
being generated in the context of software pre-fetching after a
subroutine got in-lined. (Upgrading to icc 10.0.026 makes the
workaround unnecessary.)