[libvirt] libvirt cannot be built with -Werror on RHEL6RC(x86_64)

My steps to build libvirt: 1. # export CFLAGS=-Werror 2. # ./autogen.sh 3. # make dist && rpmbuild --nodeps --define "_sourcedir `pwd`" -ba libvirt.spec ... checking for msgmerge... /usr/bin/msgmerge checking whether NLS is requested... yes checking for GNU gettext in libc... no checking for iconv... yes checking for GNU gettext in libintl... no checking whether to use NLS... no checking for UDEV... yes checking for PCIACCESS... yes ... + rm -f /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/etc/libvirt/qemu/networks/default.xml + rm -f /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/etc/libvirt/qemu/networks/autostart/default.xml + sed -i -e '/<uuid>/d' /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/usr/share/libvirt/networks/default.xml + /usr/lib/rpm/find-lang.sh /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64 libvirt No translations found for libvirt in /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64 error: Bad exit status from /var/tmp/rpm-tmp.nSgCNo (%install) RPM build errors: Bad exit status from /var/tmp/rpm-tmp.nSgCNo (%install) 4. # cat config.log ... configure:82567: checking for GNU gettext in libc configure:82596: gcc -std=gnu99 -o conftest -Werror conftest.c -ldl >&5 cc1: warnings being treated as errors conftest.c: In function 'main': conftest.c:468: error: cast from pointer to integer of different size configure:82603: $? = 1 configure: failed program was: ... | int | main () | { | bindtextdomain ("", ""); | return (int) gettext ("") + _nl_msg_cat_cntr + *_nl_domain_bindings | ; | return 0; | } configure:82623: result: no ... 5. # cat po/Makefile.in.in ... install: install-exec install-data install-exec: install-data: install-data-@USE_NLS@ if test "$(PACKAGE)" = "gettext-tools"; then \ $(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \ for file in $(DISTFILES.common) Makevars.template; do \ $(INSTALL_DATA) $(srcdir)/$$file \ $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ for file in Makevars; do \ rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ else \ : ; \ fi install-data-no: all install-data-yes: all $(mkinstalldirs) $(DESTDIR)$(datadir) ... gettext() returns char *, and we try to convert it to int. The size of pointer and int is different, and gcc will give a warning. I build it with -Werror, so the test program can not be built, and NLS is disabled. But We only install translations when NLS is enabled.

At 05/12/2011 02:40 PM, Wen Congyang Write:
My steps to build libvirt: 1. # export CFLAGS=-Werror 2. # ./autogen.sh 3. # make dist && rpmbuild --nodeps --define "_sourcedir `pwd`" -ba libvirt.spec ... checking for msgmerge... /usr/bin/msgmerge checking whether NLS is requested... yes checking for GNU gettext in libc... no checking for iconv... yes checking for GNU gettext in libintl... no checking whether to use NLS... no checking for UDEV... yes checking for PCIACCESS... yes ... + rm -f /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/etc/libvirt/qemu/networks/default.xml + rm -f /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/etc/libvirt/qemu/networks/autostart/default.xml + sed -i -e '/<uuid>/d' /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/usr/share/libvirt/networks/default.xml + /usr/lib/rpm/find-lang.sh /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64 libvirt No translations found for libvirt in /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64 error: Bad exit status from /var/tmp/rpm-tmp.nSgCNo (%install)
RPM build errors: Bad exit status from /var/tmp/rpm-tmp.nSgCNo (%install)
4. # cat config.log ... configure:82567: checking for GNU gettext in libc configure:82596: gcc -std=gnu99 -o conftest -Werror conftest.c -ldl >&5 cc1: warnings being treated as errors conftest.c: In function 'main': conftest.c:468: error: cast from pointer to integer of different size configure:82603: $? = 1 configure: failed program was: ... | int | main () | { | bindtextdomain ("", ""); | return (int) gettext ("") + _nl_msg_cat_cntr + *_nl_domain_bindings | ; | return 0; | }
This test program is generated according to gettext.m4. It's a bug of old version gettext, and it's fixed in gettext-0.14.4. I modify configure.ac to require gettext-0.14.4, build libvirt with -Werror, and receive the following error messages: RPM build errors: File not found: /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/etc/libvirt/lxc.conf File not found: /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/var/run/libvirt/lxc File not found: /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/var/lib/libvirt/lxc File not found: /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/usr/share/augeas/lenses/libvirtd_lxc.aug File not found: /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/usr/share/augeas/lenses/tests/test_libvirtd_lxc.aug File not found: /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.1-1.el6.x86_64/usr/libexec/libvirt_lxc The following patch can fix the problem:
From 95a02c3f6c594a623c01183067a1abd0d925d492 Mon Sep 17 00:00:00 2001 From: Wen Congyang <wency@cn.fujitsu.com> Date: Thu, 12 May 2011 17:51:21 +0800 Subject: [PATCH] build: fix building error with -Werror
--- configure.ac | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 71c4968..0d369ac 100644 --- a/configure.ac +++ b/configure.ac @@ -638,7 +638,10 @@ if test "$with_libvirtd" = "no" ; then with_lxc=no fi if test "$with_lxc" = "yes" || test "$with_lxc" = "check"; then - AC_TRY_LINK([#define _GNU_SOURCE + AC_TRY_LINK([ + #ifndef _GNU_SOURCE + #define _GNU_SOURCE + #endif #include <sched.h> ], [ unshare (1); @@ -1981,7 +1984,7 @@ dnl Enable building libvirtd? AM_CONDITIONAL([WITH_LIBVIRTD],[test "x$with_libvirtd" = "xyes"]) dnl Check for gettext -AM_GNU_GETTEXT_VERSION([0.14.1]) +AM_GNU_GETTEXT_VERSION([0.14.4]) AM_GNU_GETTEXT([external]) dnl Since we're using such an old version of gettext, we must also define dnl this symbol, in order to make the autopoint-supplied Makefile.in.in -- 1.7.1
configure:82623: result: no ...
5. # cat po/Makefile.in.in ... install: install-exec install-data install-exec: install-data: install-data-@USE_NLS@ if test "$(PACKAGE)" = "gettext-tools"; then \ $(mkinstalldirs) $(DESTDIR)$(gettextsrcdir); \ for file in $(DISTFILES.common) Makevars.template; do \ $(INSTALL_DATA) $(srcdir)/$$file \ $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ for file in Makevars; do \ rm -f $(DESTDIR)$(gettextsrcdir)/$$file; \ done; \ else \ : ; \ fi install-data-no: all install-data-yes: all $(mkinstalldirs) $(DESTDIR)$(datadir) ... gettext() returns char *, and we try to convert it to int. The size of pointer and int is different, and gcc will give a warning. I build it with -Werror, so the test program can not be built, and NLS is disabled. But We only install translations when NLS is enabled.
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 05/12/2011 03:55 AM, Wen Congyang wrote:
This test program is generated according to gettext.m4. It's a bug of old version gettext, and it's fixed in gettext-0.14.4.
Unfortunately, there are several other bugs in m4 files inherited as a result of our choice of gettext.
The following patch can fix the problem:
From 95a02c3f6c594a623c01183067a1abd0d925d492 Mon Sep 17 00:00:00 2001 From: Wen Congyang <wency@cn.fujitsu.com> Date: Thu, 12 May 2011 17:51:21 +0800 Subject: [PATCH] build: fix building error with -Werror
-Werror is for development, but not for rpc builds (mainly because once a tarball is created, we no longer can ensure that updates to the build toolchain won't introduce new warnings that were not present when the tarball was created, rendering -Werror on that tarball worthless). This may be a case of having to just say 'if it hurts, don't do it'.
+++ b/configure.ac @@ -638,7 +638,10 @@ if test "$with_libvirtd" = "no" ; then with_lxc=no fi if test "$with_lxc" = "yes" || test "$with_lxc" = "check"; then - AC_TRY_LINK([#define _GNU_SOURCE + AC_TRY_LINK([ + #ifndef _GNU_SOURCE + #define _GNU_SOURCE + #endif #include <sched.h>
This hunk might be worthwhile; I'll look into it more later today.
], [ unshare (1); @@ -1981,7 +1984,7 @@ dnl Enable building libvirtd? AM_CONDITIONAL([WITH_LIBVIRTD],[test "x$with_libvirtd" = "xyes"])
dnl Check for gettext -AM_GNU_GETTEXT_VERSION([0.14.1]) +AM_GNU_GETTEXT_VERSION([0.14.4])
But this hunk would likely break out-of-the-box building of libvirt on RHEL 5 and CentOS, if they don't have new enough gettext. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 05/12/2011 05:58 AM, Eric Blake wrote:
On 05/12/2011 03:55 AM, Wen Congyang wrote:
This test program is generated according to gettext.m4. It's a bug of old version gettext, and it's fixed in gettext-0.14.4.
Unfortunately, there are several other bugs in m4 files inherited as a result of our choice of gettext.
@@ -1981,7 +1984,7 @@ dnl Enable building libvirtd? AM_CONDITIONAL([WITH_LIBVIRTD],[test "x$with_libvirtd" = "xyes"])
dnl Check for gettext -AM_GNU_GETTEXT_VERSION([0.14.1]) +AM_GNU_GETTEXT_VERSION([0.14.4])
But this hunk would likely break out-of-the-box building of libvirt on RHEL 5 and CentOS, if they don't have new enough gettext.
I just confirmed that RHEL 5.6 and CentOS now ship with gettext-0.17; as does the latest cygwin. We obviously can't go to the latest upstream of 0.18.1.1 because it would alienate several live supported distros, but I see no point of limiting ourselves to 0.14.x if moving all the way to 0.17 works. Are any other popular distros stuck on something older than 0.17? -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 05/12/2011 05:58 AM, Eric Blake wrote:
+++ b/configure.ac @@ -638,7 +638,10 @@ if test "$with_libvirtd" = "no" ; then with_lxc=no fi if test "$with_lxc" = "yes" || test "$with_lxc" = "check"; then - AC_TRY_LINK([#define _GNU_SOURCE + AC_TRY_LINK([ + #ifndef _GNU_SOURCE + #define _GNU_SOURCE + #endif #include <sched.h>
This hunk might be worthwhile; I'll look into it more later today.
Here, the problem was that gl_INIT already AC_DEFINE'd _GNU_SOURCE, but with a value of 1. It's actually an error to redefine a macro if the redefinition is not to the identical value, but since it guaranteed to already be defined, we can simplify your patch. I'm pushing this simpler fix in your name: From 1ba6e2d926dadd6267084fe0b27209ba6c1099ff Mon Sep 17 00:00:00 2001 From: Wen Congyang <wency@cn.fujitsu.com> Date: Thu, 12 May 2011 17:55:43 +0800 Subject: [PATCH] build: avoid compiler warning during configure There is no need to redefine _GNU_SOURCE in tests that occur after gl_INIT, since that macro already AC_DEFINE'd it for us. Signed-off-by: Eric Blake <eblake@redhat.com> --- configure.ac | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/configure.ac b/configure.ac index 71c4968..a2ce97e 100644 --- a/configure.ac +++ b/configure.ac @@ -638,7 +638,7 @@ if test "$with_libvirtd" = "no" ; then with_lxc=no fi if test "$with_lxc" = "yes" || test "$with_lxc" = "check"; then - AC_TRY_LINK([#define _GNU_SOURCE + AC_TRY_LINK([ #include <sched.h> ], [ unshare (1); -- 1.7.4.4 -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 05/12/2011 12:40 AM, Wen Congyang wrote:
My steps to build libvirt: 1. # export CFLAGS=-Werror
The general advice from the gnulib list is that using -Werror during the duration of ./configure is unsupported. There are a number of gnulib-supplied configure tests that get the wrong answer if -Werror is on too early, with no plans to fix those upstream in gnulib, so downstream libvirt cannot control all the problems caused by adding -Werror to CFLAGS before configure. Rather, it's better to rely on the ./configure --enable-compile-warnings=error, which libvirt uses to probe if -Werror works, then ensure that -Werror is used during the Makefile when building sane code, but omitted during configure tests where the code is intentionally hairy. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Wen Congyang