Bug #268 compiling failed on Linux with gcc compiler using branch-probabilities
Submitted: 9 Apr 2003 23:24 Modified: 26 Apr 2003 5:51
Reporter: Chiiwen Liou Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S2 (Serious)
Version:4.1 OS:Linux (Linux Redhat 8.0)
Assigned to: Michael Widenius CPU Architecture:Any

[9 Apr 2003 23:24] Chiiwen Liou
Description:
Using following command will got compiling errors
CC=gcc CFLAGS="-O2 -fbranch-probabilities"   CXX=gcc \
CXXFLAGS="-O2  -fbranch-probabilities -felide-constructors -fno-exceptions  -fno-rtti " \
configure --prefix=/usr/local --with-debug --with-extra-charsets=complex
make

Errors as follows:
make[2]: Entering directory `/home/chiiwen/mysql-4.1/libmysql'
source='libmysql.c' object='libmysql.lo' libtool=yes \
depfile='.deps/libmysql.Plo' tmpdepfile='.deps/libmysql.TPlo' \
depmode=gcc3 /bin/sh ../depcomp \
/bin/sh ../libtool --mode=compile gcc -DDEFAULT_CHARSET_HOME="\"/usr/local\"" -DDATADIR="\"/usr/local/var\"" -DSHAREDIR="\"/usr/local/share/mysql\"" -DUNDEF_THREADS_HACK -DDONT_USE_RAID  -DMYSQL_CLIENT -I. -I. -I.. -I../include     -g -O -DDBUG_ON -DSAFE_MUTEX -O2 -fbranch-probabilities  -c -o libmysql.lo `test -f 'libmysql.c' || echo './'`libmysql.c
gcc -DDEFAULT_CHARSET_HOME=\"/usr/local\" -DDATADIR=\"/usr/local/var\" -DSHAREDIR=\"/usr/local/share/mysql\" -DUNDEF_THREADS_HACK -DDONT_USE_RAID -DMYSQL_CLIENT -I. -I. -I.. -I../include -g -O -DDBUG_ON -DSAFE_MUTEX -O2 -fbranch-probabilities -c libmysql.c -MT libmysql.lo -MD -MP -MF .deps/libmysql.TPlo
libmysql.c:0: warning: file libmysql.da not found, execution counts assumed to be zero
libmysql.c: In function `mysql_real_connect':
libmysql.c:2177: warning: passing arg 5 of `gethostbyname_r' from incompatible pointer type
libmysql.c:2177: too few arguments to function `gethostbyname_r'
libmysql.c:2177: warning: assignment makes pointer from integer without a cast
make[2]: *** [libmysql.lo] Error 1
make[2]: Leaving directory `/home/chiiwen/mysql-4.1/libmysql'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/chiiwen/mysql-4.1'
make: *** [all] Error 2

How to repeat:
CC=gcc CFLAGS="-O2 -fbranch-probabilities"   CXX=gcc \
CXXFLAGS="-O2  -fbranch-probabilities -felide-constructors -fno-exceptions  -fno-rtti " \
configure --prefix=/usr/local --with-debug --with-extra-charsets=complex
make

Suggested fix:
It seems we need to add line number 21209-21220 to avoid compiling errors.

  21207 #---START: Used in for client configure
  21208 
  21209 # Check definition of gethostbyname_r (glibc2.0.100 is different from Solaris)
  21210 ac_save_CXXFLAGS="$CXXFLAGS"
  21211 # Do not treat warnings as errors if we are linking against other libc
  21212 # this is to work around gcc not being permissive on non-system includes
  21213 # with respect to ANSI C++
  21214 # We also remove the -fbranch-probabilities option as this will give warnings
  21215 # about not profiled code, which confuses configure
  21216 if test "$ac_cv_cxx_compiler_gnu" = "yes" -a "$with_other_libc" = "no"
  21217 then
  21218   CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'`
  21219 fi
  21220 
  21221 echo "$as_me:$LINENO: checking style of gethostname_r routines" >&5
  21222 echo $ECHO_N "checking style of gethostname_r routines... $ECHO_C" >&6
  21223 if test "${mysql_cv_gethostname_style+set}" = set; then
  21224   echo $ECHO_N "(cached) $ECHO_C" >&6
  21225 else
[9 Apr 2003 23:32] Chiiwen Liou
Suggest fixes resolve current errors, but there is still another errors need to resolve.

---------errors after first fixes-----------------
gcc -DMYSQL_SERVER -DDEFAULT_MYSQL_HOME="\"/usr/local\"" -DDATADIR="\"/usr/local/var\"" -DSHAREDIR="\"/usr/local/share/mysql\"" -DHAVE_CONFIG_H -I. -I. -I.. -I../innobase/include -I../include -I../regex -I.     -g -O -DSAFE_MUTEX -O2  -fbranch-probabilities -felide-constructors -fno-exceptions  -fno-rtti   -fno-implicit-templates -fno-exceptions -fno-rtti -DUSE_MYSYS_NEW -DDEFINE_CXA_PURE_VIRTUAL -c -o mysqld.o `test -f 'mysqld.cc' || echo './'`mysqld.cc
mysqld.cc:0: warning: file mysqld.da not found, execution counts assumed to be
   zero
mysqld.cc: In function `void* handle_connections_sockets(void*)':
mysqld.cc:2944: invalid conversion from `size_socket*' to `socklen_t*'
mysqld.cc:3017: invalid conversion from `size_socket*' to `socklen_t*'
[10 Apr 2003 0:12] Chiiwen Liou
It need second fixes on configure (line 16935 to 16944). Of course, the real fix is in configure.in. 
  16930 #---START: Used in for client configure
  16931 # Check base type of last arg to accept
  16932 
  16933 ac_save_CXXFLAGS="$CXXFLAGS"
  16934 
  16935 # Do not treat warnings as errors if we are linking against other libc
  16936 # this is to work around gcc not being permissive on non-system includes
  16937 # with respect to ANSI C++
  16938 # We also remove the -fbranch-probabilities option as this will give warnings
  16939 # about not profiled code, which confuses configure
  16940 if test "$ac_cv_cxx_compiler_gnu" = "yes" -a "$with_other_libc" = "no"
  16941 then
  16942   CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'`
  16943 fi
  16944 
  16945 echo "$as_me:$LINENO: checking base type of last arg to accept" >&5
  16946 echo $ECHO_N "checking base type of last arg to accept... $ECHO_C" >&6
[12 Apr 2003 12:41] Chiiwen Liou
Here is a fix for configure.in that works.
-----------
>diff configure.in  configure.in.new 
1877a1878,1882
> # Do not treat warnings as errors if we are linking against other libc
> # this is to work around gcc not being permissive on non-system includes
> # with respect to ANSI C++
> # We also remove the -fbranch-probabilities option as this will give warnings
> # about not profiled code, which confuses configure
1880c1885
<   CXXFLAGS="$CXXFLAGS -Werror"
---
>   CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'`
[14 Apr 2003 1:58] Lenz Grimmer
Thanks for the info - assigned bug report to me to apply the 
patch.
[14 Apr 2003 8:14] Chiiwen Liou
My previous fix is not complete. Here is a more complete one.
---
mysql-4.1 <88> diff configure.in configure.in.new
1877a1878,1882
> # Do not treat warnings as errors if we are linking against other libc
> # this is to work around gcc not being permissive on non-system includes
> # with respect to ANSI C++
> # We also remove the -fbranch-probabilities option as this will give warnings
> # about not profiled code, which confuses configure
1880c1885
<   CXXFLAGS="$CXXFLAGS -Werror"
---
>   CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'`
1912c1917
<   CXXFLAGS="$CXXFLAGS -Werror"
---
>   CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'`
-------------
Now I have problems on config.h. The new config.h is not correct. I do not know why....
mysql-4.1 <93> diff config.h config.h.new
269c269
< #define SOCKET_SIZE_TYPE int
---
> #define SOCKET_SIZE_TYPE socklen_t
[14 Apr 2003 18:07] Chiiwen Liou
Here is the fix for correct config.h
----------------------
mysql-4.1 <75> diff acinclude.m4 acinclude.m4.new
81c81
<   CXXFLAGS="$CXXFLAGS -Werror"
---
>   CXXFLAGS=`echo "$CXXFLAGS -Werror" | sed 's/-fbranch-probabilities//'`

----------------------
So there are 2 files need to modify (configure.in & acinclude.m4)
[25 Apr 2003 13:41] Lenz Grimmer
Monty, ok to apply?
[26 Apr 2003 5:51] Michael Widenius
Thank you for your bug report. This issue has been fixed in the latest
development tree for that product. You can find more information about
accessing our development trees at 
    http://www.mysql.com/doc/en/Installing_source_tree.html

Fixed in 4.0 tree;  Will automaticly propagate to 4.1 tree...
[28 Apr 2003 2:41] Lenz Grimmer
Fixed with this ChangeSet: 
 
ChangeSet@1.1473, 2003-04-26 20:43:28+03:00, 
monty@mashka.mysql.fi 
  Fix for -fbranch-probabilites (bug 268)
[30 Apr 2003 21:09] Chiiwen Liou
When this fix will propagate to 4.1 & 5.0?
[2 May 2003 2:02] Lenz Grimmer
As soon as Monty will do the merge of 4.0 -> 4.1 (usually before a new 4.1 release is being cut) 
There is no definitive date for that yet, but it will very likely happen within this month.