Bug #19694 prepared statements broken when compiling with gcc-4
Submitted: 10 May 2006 17:36 Modified: 3 Jul 2006 20:09
Reporter: Jens Theisen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Prepared statements Severity:S2 (Serious)
Version:4.1.19 OS:Linux (GNU/Linux)
Assigned to: Michael Widenius CPU Architecture:Any

[10 May 2006 17:36] Jens Theisen
Description:
The MySQL test suite is broken, specifically the test_prepare function
in mysql_client_test, and probably more; the statement is prepared
correctly, but the bound data sent is rubbish.

I compiled from source with gcc-4.0.3, configured and compiled without
any options.

It works when compiling with an earlier compiler and unfortunately
also when configuring with --with-debug.

I could also narrow it down to it being on the server side and in the
C++ side (by compiling only the respective parts with the newer
compiler).

I'd liked to investigate further myself, but without debugging symbols
I'm at a loss what to do.

Note that I don't really need a fix myself immediately, as I can
happily compile with gcc 3.4.

How to repeat:
Run the test suite after compiling with gcc-4 on GNU/Linux (tried on both 32 and 64 bit).
[10 May 2006 17:39] Jens Theisen
I should add the tested architectures: AMD64 and x86.
[11 May 2006 11:13] Hartmut Holzgraefe
Fails with both gcc-4.0.3 and gcc-4.0.2 (default compiler on SuSE 10.0)

TEST                            RESULT
-------------------------------------------------------
mysql_client_test              [ fail ]

Errors are (from /home/hartmut/projects/mysql/releases/mysql-4.1.19/mysql-test/var/log/mysqltest-time) :
mysql_client_test.c:3573: check failed: '(int) i8_data == rc'
mysqltest: At line 10: command "$MYSQL_CLIENT_TEST --getopt-ll-test=25600M" failed
(the last lines may be the most important ones)
[12 May 2006 12:38] Chad MILLER
I can't reproduce.

mysql-4.1__bug19694/mysql-test $ ./mysql-test-run.pl --debug mysql_client_test

TEST                           RESULT
-------------------------------------------------------

mysql_client_test              [ pass ]
-------------------------------------------------------
Ending Tests
Shutting-down MySQL daemon

Master(s) shutdown finished
Slave(s) shutdown finished
All 1 tests were successful.

mysql-4.1__bug19694/mysql-test $ gcc -v Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --with-tune=pentium4 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)
[12 May 2006 14:33] Jani Tolonen
Unable to reproduce with latest 4.1 source, last changeset:

ChangeSet@1.2470.1.3, 2006-05-10 21:53:01+02:00, kent@mysql.com
mysql.spec.sh:
Compile in all character sets in Max (bug#14918)

gcc --version
gcc (GCC) 4.0.2 20050901 (prerelease) (SUSE Linux)
Copyright (C) 2005 Free Software Foundation, Inc.

uname -a

Linux a193-229-222-105 2.6.13-15.8-smp #1 SMP Tue Feb 7 11:07:24 UTC 2006 i686 i686 i386 GNU/Linux

SuSE 10 installation.

The test passes.
[12 May 2006 15:49] Chad MILLER
Ah, I can now.  The problem disappears if one turns on our debugging flags.

I'm claiming this bug.
[5 Jun 2006 10:06] Michael Widenius
Verified with  5.1.12 tree and gcc 4.0.2

It's look like this is a client only problem (either mysql_client_test or libmysql.c) as this only happens with a client compiled with optimzation (and maybe with gcc 4.0?) becasue if I recompile just the client part and run it against an optimized mysqld version, the test succeeds.

Fast way to test this is to start mysqld in a debugger and run from the command line:

 ./tests/mysql_client_test test_fetch_float

Until we know the exact cause of the problem, we should treat this as a critical error as we don't know what other similar errors could exists
[5 Jun 2006 10:24] Konstantin Osipov
Bug#20266 has been marked as a duplicate of this bug.
[6 Jun 2006 4:13] Elliot Murphy
Bug#20175 has been marked a duplicate of bug#20266, which was marked a duplicate of this bug. Setting to P1 as Bug#20175 is a crash.
[29 Jun 2006 23:23] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/8519
[30 Jun 2006 0:50] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/8526
[30 Jun 2006 14:52] Michael Widenius
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://www.mysql.com/doc/en/Installing_source_tree.html

This bug affected prepared statements with result sets that returned float (but not not double) values that was bound to an int8 value.

The problem was wrong cast usage that caused gcc 4.0 to produce wrong code when using both options: -fstrict-aliasing and -fschedule-insns2, which are set when using -O2. (This was found by changing -O3 in libmysql/Makefile to -O1 and add different -O2 options to compile line until test started failing)

Fix will be in 4.0.21, 5.0.24 and 5.1.13
[30 Jun 2006 14:52] Michael Widenius
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://www.mysql.com/doc/en/Installing_source_tree.html

This bug affected prepared statements with result sets that returned float (but not not double) values that was bound to an int8 value.

The problem was wrong cast usage that caused gcc 4.0 to produce wrong code when using both options: -fstrict-aliasing and -fschedule-insns2, which are set when using -O2. (This was found by changing -O3 in libmysql/Makefile to -O1 and add different -O2 options to compile line until test started failing)

Fix will be in 4.1.21, 5.0.24 and 5.1.13
[3 Jul 2006 20:09] Paul DuBois
Noted in 4.1.21, 5.0.24, and 5.1.12 (there is no 5.1.13 yet)
changelogs.

A cast problem caused incorrect results for prepared statements that
returned float values when MySQL was compiled with gcc 4.0.
[13 Jul 2006 3:42] Paul DuBois
5.0.x fix went to 5.0.25 instead.
[28 Sep 2006 22:40] Joshua Hoblitt
I just encountered this exact same issue building 4.1.21 on amd64 with gcc 4.1.1.  Is this fix really in 4.1.21 or is it actually in 4.1.22?  Rebuliding with gcc 3.4.6 resolved the issue.