Bug #9342 Calling functions fails when compiled with Sun C compiler
Submitted: 22 Mar 2005 18:04 Modified: 7 Jul 2005 16:09
Reporter: Jim Winstead Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S2 (Serious)
Version:5.0 OS:Sun Solaris 10 on AMD64
Assigned to: Jim Winstead CPU Architecture:Any

[22 Mar 2005 18:04] Jim Winstead
Description:
When compiled using the Sun C compiler's -xO3 flag, the server fails to handle calls to built-in functions correctly. It appears that the get_hash_symbol() function defined in sql/lex_hash.h is optimized in a way that causes it to fail to work. (This was determined by adding extra debug output to that function.)

How to repeat:
1. Download the 5.0.3 source (once released).
2. Configure on Solaris AMD64 using:

   CC=cc CXX=CC CFLAGS="-xO3 -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all -xlibmil -xlibmopt -xtarget=opteron -xarch=amd64" CXXFLAGS="-xO3 -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all -xlibmil -xlibmopt -xtarget=opteron -xarch=amd64"  ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --libexecdir=/usr/local/mysql/bin --with-comment="MySQL Community Edition - Debug (GPL)" --with-extra-charsets=complex --with-server-suffix="-debug" --enable-thread-safe-client --enable-local-infile --with-named-curses=-lcurses --disable-shared --with-debug --with-readline --with-embedded-server --with-archive-storage-engine --with-innodb

  (This is our standard debug build.)

  cc is Sun C 5.7 2005/01/07.

3. Run the server, and try to call a function like "SELECT VERSION()". (Or just run one of the many tests that call functions.)

Suggested fix:
Compiling with "-xO1" instead of "-xO3" avoids the issue. It appears to be a bug in the optimizations done by the Sun compiler.
[22 Apr 2005 21:18] luojia chen
I have re-produced the problems of using "-xO3" with Sun Studio 10 to build the 64-bit MySQL on the Sol 10 x86 box. However, when I ran some test, for example,"mysql-run-test alias", looks like the "get_hash_symbol()" was not called duing the test by my adding some
debug messages on the get_hash_symbol()(it shows that get_hash_symbol() was called and exit before the "alias" test). So please let me know how come you get the conclusion that it is the get_hash_symbol() cause that using optimization level "-xO3" failed with the test. Could you attach the file defining get_hash_symbol() added with the debug messages, and let me know by running which test, it show the get_hash_symbol() failed?
[26 Apr 2005 19:12] Jim Winstead
With this patch to lex_casecmp() to see where it is being called:

@@ -72,9 +72,11 @@
 
 inline int lex_casecmp(const char *s, const char *t, uint len)
 {
+  DBUG_ENTER("lex_casecmp");
+  DBUG_PRINT("info",("check '%s' against '%s' (%d)", s, t, len));
   while (len-- != 0 &&
         to_upper_lex[(uchar) *s++] == to_upper_lex[(uchar) *t++]) ;
-  return (int) len+1;
+  DBUG_RETURN((int) len+1);
 }

And then running mysql-test-run --debug on a simple test that just calls 'SELECT VERSION()', I get this in the mysql-test/var/log/master.trace file:

T@10   : | | >lex_casecmp
T@10   : | | | info: check 'ect version()' against 'ECT' (3)
T@10   : | | <lex_casecmp
T@10   : | | >lex_casecmp
T@10   : | | | info: check 'rsion()' against 'EA' (5)
T@10   : | | <lex_casecmp

With a version of the server compiled with -Ox1, I get:

T@10   : | | >lex_casecmp
T@10   : | | | info: check 'ect version()' against 'ECT' (3)
T@10   : | | <lex_casecmp
T@10   : | | >lex_casecmp
T@10   : | | | info: check 'rsion()' against 'RSION' (5)
T@10   : | | <lex_casecmp

This means that get_hash_symbol() has gone astray. In the optimized (broken) case, it has gone taken 'VE' and matched it up with the 'AR' in AREA for some reason.
[23 Jun 2005 17:37] Jim Winstead
The compiler bug is in Sun's hands, and in the meantime we have cranked down the optimization setting to produce Solaris x86_64 builds.
[4 Jul 2005 19:32] Jim Winstead
According to Sun:

The patch to fix the problem of compiling MySQL with "-xO3" was just            
available on the website:                                                       
                                                                                
http://developers.sun.com/prodtech/cc/downloads/patches/ss10_patches.html       
                                                                                
Please select patch 117846-06.
[7 Jul 2005 16:09] Lenz Grimmer
We applied the patch on our Solaris10/AMD64 build machine and the code now compiles and passes the tests with -x03 enabled.