Bug #42817 Compilation error with latest MySQL 5.1 from BZR
Submitted: 13 Feb 2009 7:14 Modified: 13 Apr 2009 23:33
Reporter: Vasil Dimov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S1 (Critical)
Version:r2756 OS:FreeBSD (FreeBSD 7.1, gcc 4.2.1)
Assigned to: Kent Boortz CPU Architecture:Any

[13 Feb 2009 7:14] Vasil Dimov
Description:
Get the latest 5.1 sources from BZR, bzr revno shows 2756.

try to compile with:

./BUILD/autorun.sh && ./configure --with-plugins=innobase --with-partition --prefix=/tmp/mysql-5.1-install && gmake

I am getting this error:

gcc -DHAVE_CONFIG_H -I. -I../../include -I../../include -I../../include    -O3    -MT vi.o -MD -MP -MF .deps/vi.Tpo -c -o vi.o vi.c
vi.c:918:74: error: macro "__weak_reference" requires 2 arguments, but only 1 given
vi.c: In function 'get_alias_text':
vi.c:918: error: expected declaration specifiers before '__weak_reference'
vi.c:923: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
vi.c:953: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
vi.c:998: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
vi.c:1054: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
vi.c:1103: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
vi.c:918: error: parameter name omitted
vi.c:1124: error: expected '{' at end of input
gmake[2]: *** [vi.o] Error 1
gmake[2]: Leaving directory `/tmp/mysql-5.1/cmd-line-utils/libedit'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/tmp/mysql-5.1/cmd-line-utils'
gmake: *** [all-recursive] Error 1

This error started popping up on Feb 12 1:30 UTC, it compiled fine on Feb 11 1:30 UTC. The version that compiled on Feb 11 says revno=2770 (yeah, older version has larger revno, this is some bzr strangeness).

How to repeat:
Try to compile, see "Description".
[13 Feb 2009 8:21] Valeriy Kravchuk
I can't repeat this with gcc 3.3.5 on Linux. The only difference in vi.c compilation string is additional -DUNIV_LINUX flag after -O3. So, looks like this problem is related to gcc 4.2.x somehow.
[16 Feb 2009 18:37] MySQL Verification Team
I couldn't repeat on Fedora 10 64-bit too:

gmake[1]: Entering directory `/home/miguel/bzr/mysql-5.1-plugin/win'
gmake[1]: Nothing to be done for `all'.
gmake[1]: Leaving directory `/home/miguel/bzr/mysql-5.1-plugin/win'
[miguel@hegel mysql-5.1-plugin]$ bzr revno
2756
[miguel@hegel mysql-5.1-plugin]$ cat /etc/issue
Fedora release 10 (Cambridge)
Kernel \r on an \m (\l)

[miguel@hegel mysql-5.1-plugin]$ gcc --version
gcc (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7)
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
[19 Feb 2009 14:21] Vasil Dimov
On FreeBSD __weak_reference is defined like this in /usr/include/sys/cdefs.h:

#ifdef __STDC__
#define __weak_reference(sym,alias)     \
        __asm__(".weak " #alias);       \
        __asm__(".equ "  #alias ", " #sym)
...
#else
#define __weak_reference(sym,alias)     \
        __asm__(".weak alias");         \
        __asm__(".equ alias, sym")
...

In MySQL's cmd-line-utils/libedit/vi.c:
917 #ifdef __weak_reference
918 extern char *get_alias_text(const char *) __weak_reference(get_alias_text);
919 #endif

On a few Linux systems that I tried __weak_reference is not defined at all which explains why people do not get this compilation error on Linux.

Assigning this to joro@ who seems to be the author of the changeset that added this code:

revno: 1810.3826.4
committer: Georgi Kodinov <joro@sun.com>
branch nick: B42433-5.0-bugteam
timestamp: Tue 2009-02-10 14:39:14 +0200
message:
  From jperkin :  Merge libedit 2.11 and related files, 
  based on NetBSD CVS as of 2009/02/06 20:09:00.
[19 Feb 2009 14:27] Vasil Dimov
On NetBSD __weak_reference is defined like:

#if __GNUC_PREREQ__(4, 0)
#define	__weak_reference(sym)	__attribute__((__weakref__))
#else
#define	__weak_reference(sym)	; __asm(".weak " _C_LABEL_STRING(#sym))
#endif

see http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/cdefs_elf.h?rev=1.29.28.1&content-type=tex...

So using __weak_reference() with a single argument is not portable.
[19 Feb 2009 14:39] Georgi Kodinov
I was just pushing for jperkin :-). Re-assigned.
[23 Feb 2009 10:24] Vasil Dimov
Here is a dummy patch to make this thing compile on FreeBSD:

--- cut ---
=== modified file 'cmd-line-utils/libedit/vi.c'
--- cmd-line-utils/libedit/vi.c	2009-02-10 12:39:14 +0000
+++ cmd-line-utils/libedit/vi.c	2009-02-23 10:19:44 +0000
@@ -914,14 +914,14 @@
  * NB: posix implies that we should enter insert mode, however
  * this is against historical precedent...
  */
-#ifdef __weak_reference
+#if defined(__weak_reference) && defined(__NetBSD__)
 extern char *get_alias_text(const char *) __weak_reference(get_alias_text);
 #endif
 protected el_action_t
 /*ARGSUSED*/
 vi_alias(EditLine *el, int c)
 {
-#ifdef __weak_reference
+#if defined(__weak_reference) && defined(__NetBSD__)
 	char alias_name[3];
 	char *alias_text;
 
--- cut ---

Note: I have only tested this on FreeBSD and it compiles, but:
 * it does not use the __weak_reference() macro on FreeBSD even though it is available (with 2 arguments)
 * I have not tested on NetBSD, I do not even know whether the symbol __NetBSD__ is defined on NetBSD

This should be fixed before the next release because it breaks compilation on FreeBSD.
[9 Mar 2009 5:58] Vasil Dimov
------------------------------------------------------------
revno: 2728.10.6
tags: mysql-5.1.32
author: kent.boortz@sun.com
committer: MySQL Build Team <build@mysql.com>
branch nick: mysql-5.1.32-release
timestamp: Sat 2009-02-14 01:43:21 +0100
message:
  Disabled libedit use of '__weak_reference' on FreeBSD, doesn't compile
modified:
  cmd-line-utils/libedit/vi.c
[16 Mar 2009 19:40] Kent Boortz
This is corrected in 5.0.79 and 5.1.32
[13 Apr 2009 23:33] Paul DuBois
Noted in 5.0.79, 5.1.32 changelogs.

The use by libedit of the __weak_reference() macro caused compilation
failure on FreeBSD.
[15 Jul 2009 21:39] Steven Hartland
Same thing happens on cygwin 1.7