Using the recent 3.2 clang and gold plugin, I failed to compile MySQL with lto to generate bc files, where 3.0 version has no problems. Tested MySQL version: ===================== * 5.1.67, 5.1.50 Tested OS versions: =================== * Ubuntu 11.04 with tool chain gcc 4.5.2, binutils 2.23 with gold plugin enabled * CentOS 6.3 with tool chain gcc 4.4.6, binutils 2.23 with gold plugin enabled Steps to reproduce: =================== 0. Setup gold plugin: * /home/ryan/software/binutils/build/2.23 is where the binutils are installed * /home/ryan/software/llvm/build/3.2 is where LLVM is installed * cd /home/ryan/software/binutils/build/2.23/bin * cp ld ld.default * cp ld.gold ld * cd ../lib * mkdir bfd-plugins * cd bfd-plugins * ln -s /home/ryan/software/llvm/build/3.2/lib/LLVMgold.so * Put /home/ryan/software/binutils/build/2.23/bin in PATH 1. Setup ENV: export CC="clang -use-gold-plugin -flto" export CXX="clang++ -use-gold-plugin -flto" export CFLAGS="-g -O0" export CXXFLAGS="-g -O0" export RANLIB=/bin/true 1.1 Additional setup for 3.2 export AR="clang-ar" export NM="nm --plugin /home/ryan/software/llvm/build/3.2/lib/LLVMgold.so" where `clang-ar` is a wrapper put in /home/ryan/software/binutils/build/2.23/bin/ Its content: #!/bin/sh firstarg=${1} shift exec /home/ryan/software/binutils/build/2.23/bin/ar "${firstarg}" --plugin /home/ryan/software/llvm/build/3.2/lib/LLVMgold.so "${@}" 2. Compile MySQL * Modify the Makefile.am and Makefile.in in the unpacked mysql source, say mysql-5.1.67: remove/comment the block in `do_abi_check` at line 312. * ./configure * make -j4 Expected result: =================== In 3.0 versions, there's no compilation error and after the compilation is finished, there're bc files generated. In 3.2 version, there's error as attached in the end. From MySQL's document http://dev.mysql.com/doc/refman/5.1/en/compilation-problems.html It seems like `configure` script is misbehaving, but I guess this might relate to some changes in clang. > "By default, the configure script attempts to determine the correct number of arguments by using g++ (the GNU C++ compiler). This test yields incorrect results if g++ is not installed..." Error Messages: =============== libtool: compile: clang -use-gold-plugin -flto -DDEFAULT_CHARSET_HOME=\"/usr/local\" -DMYSQL_DATADIR=\"/usr/local/var\" -DDEFAULT_HOME_ENV=MYSQL_HOME -DDEFAULT_GROUP_SUFFIX_ENV=MYSQL_GROUP_SUFFIX -DDEFAULT_SYSCONFDIR=\"/usr/local/etc\" -DSHAREDIR=\"/usr/local/share/mysql\" -DMYSQL_CLIENT_NO_THREADS -DDONT_USE_RAID -I. -I../include -I../include -I../include -g -O0 -DUNIV_LINUX -DUNIV_LINUX -MT password.lo -MD -MP -MF .deps/password.Tpo -c password.c -o password.o >/dev/null 2>&1 manager.c:132:10: error: too few arguments to function call, expected 6, have 5 hp = my_gethostbyname_r(host,&tmp_hostent,buff2,sizeof(buff2), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../include/my_net.h:113:74: note: expanded from macro 'my_gethostbyname_r' #define my_gethostbyname_r(A,B,C,D,E) gethostbyname_r((A),(B),(C),(D),(E)) ~~~~~~~~~~~~~~~ ^ /usr/include/netdb.h:180:1: note: 'gethostbyname_r' declared here extern int gethostbyname_r (__const char *__restrict __name, ^ 1 error generated. make[2]: *** [manager.lo] Error 1 make[2]: *** Waiting for unfinished jobs....
Related bugreport (no resolution) http://www.freebsd.org/cgi/query-pr.cgi?pr=167805
gethostbyname_r is declared to take 6 arguments: int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); but it is only being passed 5 arguments: #define my_gethostbyname_r(A,B,C,D,E) gethostbyname_r((A),(B),(C),(D),(E)) So the clang error message "error: too few arguments to function call, expected 6, have 5" seems to be correct (no value passed for errnop). In short, this looks like a MySQL bug.
I just nailed down that it's related to different results of checking gethostbyname style in `configure`: In clang 3.0, the config.log snippet is: > configure:39208: checking style of gethostbyname_r routines > configure:39257: clang++ -use-gold-plugin -flto -c -g -O0 -fno-implicit-templates -fno-exceptions -fno-rtti -Werror conftest.cpp >&5 > clang: warning: argument unused during compilation: '-fno-implicit-templates' > configure:39264: $? = 0 > configure:39279: result: glibc2 So the detection result is glibc2 But in clang 3.2, the snippet is: > configure:39208: checking style of gethostbyname_r routines > configure:39257: clang++ -use-gold-plugin -flto -c -g -O0 -fno-implicit-templates -fno-exceptions -fno-rtti -Werror conftest.cpp >&5 > clang: error: argument unused during compilation: '-fno-implicit-templates' > configure:39264: $? = 1 > configure: failed program was: > | /* confdefs.h. */ > | #define PACKAGE_NAME "MySQL Server" > | #define PACKAGE_TARNAME "mysql" > ... > | #define HAVE_DECL_MADVISE 1 > | /* end confdefs.h. */ > | #undef inline > | #if !defined(SCO) && !defined(__osf__) && !defined(_REENTRANT) > | #define _REENTRANT > | #endif > | #include <pthread.h> > | #include <sys/types.h> > | #include <sys/socket.h> > | #include <netinet/in.h> > | #include <arpa/inet.h> > | #include <netdb.h> > | int > | main () > | { > | int skr; > | > | skr = gethostbyname_r((const char *) 0, > | (struct hostent*) 0, (char*) 0, 0, (struct hostent **) 0, &skr); > | ; > | return 0; > | } > configure:39279: result: other The detection result becomes other. Is it because the unused option "-fno-implicit-templates" became an error in 3.2 as opposed to warning in 3.0? Thanks! (In reply to comment #2) > gethostbyname_r is declared to take 6 arguments: > > int gethostbyname_r(const char *name, > struct hostent *ret, char *buf, size_t buflen, > struct hostent **result, int *h_errnop); > > but it is only being passed 5 arguments: > > #define my_gethostbyname_r(A,B,C,D,E) gethostbyname_r((A),(B),(C),(D),(E)) > > > So the clang error message "error: too few arguments to function call, > expected > 6, have 5" seems to be correct (no value passed for errnop). > > In short, this looks like a MySQL bug.
Created attachment 9987 [details] reduced test case This is a reduced test case for the different behaviors of clang 3.0 and 3.2. clang++ -use-gold-plugin -flto -c -g -O0 -fno-implicit-templates -fno-exceptions -fno-rtti -Werror gethostname.cc In 3.0: clang: warning: argument unused during compilation: '-fno-implicit-templates' echo $? 0 In 3.2 clang: error: argument unused during compilation: '-fno-implicit-templates' echo $? 1
In my opinion, Clang 3.2 is correct. It does what the user asked: promotes warnings to errors.
Closing per comment 5.
Reopening as I believe the bug is not INVALID. The problem here is that clang defines __GNUC__ but isn't 100% compatible with gcc. If clang pretends to be GNUC then it has to accept all flags that would be accepted by gcc. The only sane resolution I can see is to implement functionality of the missing flags or if not feasible do not promote those specific flags to errors even if -Werror is set. Again, clang is already doing the wrong thing by defining __GNUC__ (probably for compatibility reasons). For the same reasons "-Werror -fno-implicit-templates" should not produce errors.
We are not going to stop defining __GNUC__.
It is of course acceptable. This bug is not about stopping defining __GNUC__. This bug is about compatibility issues as a result of defining __GNUC__ and what could be done to reduce the negative impact of this #define.
(In reply to comment #9) > It is of course acceptable. This bug is not about stopping defining __GNUC__. > > This bug is about compatibility issues as a result of defining __GNUC__ and > what could be done to reduce the negative impact of this #define. Defining __GNUC__ is not connected with supporting all possible knobs and options of gcc (some of them are essentially implementation-defined), after all, different gcc versions have different cmdline options. Even more, the option in question does not influence the results of the test, so it should not be there after all (and it's somehow strange to use C++ compiler for C-level checks... what's about different inline semantics?). clang is not going to emulate MySQL configure checks' bugs, really. > For the same reasons "-Werror -fno-implicit-templates" should not produce errors. It should. You explicitly ask for warning here. You got the warning. It's upgraded to error. This is how -Werror works. Please move such discussion to llvm-dev, bugzilla is an inappropriate place for this.