[libvirt] [PATCH] build: fix build at -O2 on rawhide

Eric Blake eblake at redhat.com
Fri Dec 2 20:00:45 UTC 2011

I had previously tested commit 059d746 with -O intentionally omitted
from my CFLAGS; but that means that I missed out on this warning
from gcc 4.6.2 when optimizations are enabled:

util/buf.c: In function 'virBufferGetIndent':
util/buf.c:86:1: error: function might be candidate for attribute 'pure' [-Werror=suggest-attribute=pure]

While it is probably a good idea to add the attributes and silence
this warning, it's also invasive; 'make -k' found more than 75 such
complaints.  And it doesn't help that gcc 4.6.2 is still buggy
(coreutils reported a case where gcc 4.6.2 incorrectly suggested
marking a function pure that incremented a global variable; fixed
in gcc 4.7).  So the best fix for now is to disable the warning.

It also doesn't help that I stumbled across another problem - gcc
documents that -Wsuggest-attribute=pure only warns if you use -O,
or if you use -fipa-pure-const.  But in practice, when I omitted -O
but added -fipa-pure-const, the warnings are fickle - I got warnings
for simple compilation that disappeared when I also added -fPIC.
And the way libtool compiles things is with -fPIC first, then without
-fPIC but with errors sent to /dev/null - which meant that without
disabling -Wsuggest-attribute=pure, I got a compile error with no
message.  :(  See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10197

* m4/virt-compile-warnings.m4 (LIBVIRT_COMPILE_WARNINGS): Silence
-Wsuggest-attribute warnings for now.

Pushing under the build-breaker rule.

 m4/virt-compile-warnings.m4 |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index 213b3db..34a89c9 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4

+        # Need -fipa-pure-const in order to make -Wsuggest-attribute=pure
+        # fire even without -O.
+        gl_WARN_ADD([-fipa-pure-const])
+        # We should eventually enable this, but right now there are at
+        # least 75 functions triggering warnings.
+        gl_WARN_ADD([-Wno-suggest-attribute=pure])
+        gl_WARN_ADD([-Wno-suggest-attribute=const])
         if test "$enable_compile_warnings" = "error"

More information about the libvir-list mailing list