The macros under the m4 directory are outdated a bit. When trying
to compile with newer gcc I see some errors:
ACK. The update to m4/warnings.m4 is not really needed, but it does
not hurt :)
make[2]: Entering directory
'/home/zippy/work/libvirt/libvirt-glib.git/libvirt-glib'
CC libvirt_glib_1_0_la-libvirt-glib-error.lo
gcc: warning: switch '-Wmudflap' is no longer supported
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
m4/manywarnings.m4 | 217 ++++++++++++++++++++++++++++----------------
m4/virt-compile-warnings.m4 | 214 ++++++++++++++++++++++++++++++++-----------
m4/warnings.m4 | 2 +-
3 files changed, 299 insertions(+), 134 deletions(-)
diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index fd0e372..3e6dd21 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -1,5 +1,5 @@
-# manywarnings.m4 serial 3
-dnl Copyright (C) 2008-2012 Free Software Foundation, Inc.
+# manywarnings.m4 serial 7
+dnl Copyright (C) 2008-2014 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -35,14 +35,12 @@ AC_DEFUN([gl_MANYWARN_COMPLEMENT],
# make sure your gcc understands it.
AC_DEFUN([gl_MANYWARN_ALL_GCC],
[
- dnl First, check if -Wno-missing-field-initializers is needed.
- dnl -Wmissing-field-initializers is implied by -W, but that issues
- dnl warnings with GCC version before 4.7, for the common idiom
- dnl of initializing types on the stack to zero, using { 0, }
+ dnl First, check for some issues that only occur when combining multiple
+ dnl gcc warning categories.
AC_REQUIRE([AC_PROG_CC])
if test -n "$GCC"; then
- dnl First, check -W -Werror -Wno-missing-field-initializers is supported
+ dnl Check if -W -Werror -Wno-missing-field-initializers is supported
dnl with the current $CC $CFLAGS $CPPFLAGS.
AC_MSG_CHECKING([whether -Wno-missing-field-initializers is supported])
AC_CACHE_VAL([gl_cv_cc_nomfi_supported], [
@@ -77,108 +75,171 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
])
AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
fi
+
+ dnl Next, check if -Werror -Wuninitialized is useful with the
+ dnl user's choice of $CFLAGS; some versions of gcc warn that it
+ dnl has no effect if -O is not also used
+ AC_MSG_CHECKING([whether -Wuninitialized is supported])
+ AC_CACHE_VAL([gl_cv_cc_uninitialized_supported], [
+ gl_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -Werror -Wuninitialized"
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[]], [[]])],
+ [gl_cv_cc_uninitialized_supported=yes],
+ [gl_cv_cc_uninitialized_supported=no])
+ CFLAGS="$gl_save_CFLAGS"])
+ AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported])
+
fi
+ # List all gcc warning categories.
+ # To compare this list to your installed GCC's, run this Bash command:
+ #
+ # comm -3 \
+ # <(sed -n 's/^ *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \
+ # <(gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort |
+ # grep -v -x -f <(
+ # awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
+
gl_manywarn_set=
for gl_manywarn_item in \
- -Wall \
-W \
- -Wformat-y2k \
- -Wformat-nonliteral \
- -Wformat-security \
- -Winit-self \
- -Wmissing-include-dirs \
- -Wswitch-default \
- -Wswitch-enum \
- -Wunused \
- -Wunknown-pragmas \
- -Wstrict-aliasing \
- -Wstrict-overflow \
- -Wsystem-headers \
- -Wfloat-equal \
- -Wtraditional \
- -Wtraditional-conversion \
- -Wdeclaration-after-statement \
- -Wundef \
- -Wshadow \
- -Wunsafe-loop-optimizations \
- -Wpointer-arith \
- -Wbad-function-cast \
- -Wc++-compat \
- -Wcast-qual \
- -Wcast-align \
- -Wwrite-strings \
- -Wconversion \
- -Wsign-conversion \
- -Wlogical-op \
- -Waggregate-return \
- -Wstrict-prototypes \
- -Wold-style-definition \
- -Wmissing-prototypes \
- -Wmissing-declarations \
- -Wmissing-noreturn \
- -Wmissing-format-attribute \
- -Wpacked \
- -Wpadded \
- -Wredundant-decls \
- -Wnested-externs \
- -Wunreachable-code \
- -Winline \
- -Winvalid-pch \
- -Wlong-long \
- -Wvla \
- -Wvolatile-register-var \
- -Wdisabled-optimization \
- -Wstack-protector \
- -Woverlength-strings \
- -Wbuiltin-macro-redefined \
- -Wmudflap \
- -Wpacked-bitfield-compat \
- -Wsync-nand \
- ; do
- gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
- done
- # The following are not documented in the manual but are included in
- # output from gcc --help=warnings.
- for gl_manywarn_item in \
- -Wattributes \
- -Wcoverage-mismatch \
- -Wmultichar \
- -Wunused-macros \
- ; do
- gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
- done
- # More warnings from gcc 4.6.2 --help=warnings.
- for gl_manywarn_item in \
-Wabi \
+ -Waddress \
+ -Waggressive-loop-optimizations \
+ -Wall \
+ -Warray-bounds \
+ -Wattributes \
+ -Wbad-function-cast \
+ -Wbuiltin-macro-redefined \
+ -Wcast-align \
+ -Wchar-subscripts \
+ -Wclobbered \
+ -Wcomment \
+ -Wcomments \
+ -Wcoverage-mismatch \
-Wcpp \
+ -Wdate-time \
-Wdeprecated \
-Wdeprecated-declarations \
+ -Wdisabled-optimization \
-Wdiv-by-zero \
-Wdouble-promotion \
+ -Wempty-body \
-Wendif-labels \
+ -Wenum-compare \
-Wextra \
-Wformat-contains-nul \
-Wformat-extra-args \
+ -Wformat-nonliteral \
+ -Wformat-security \
+ -Wformat-y2k \
-Wformat-zero-length \
- -Wformat=2 \
+ -Wfree-nonheap-object \
+ -Wignored-qualifiers \
+ -Wimplicit \
+ -Wimplicit-function-declaration \
+ -Wimplicit-int \
+ -Winit-self \
+ -Winline \
+ -Wint-to-pointer-cast \
+ -Winvalid-memory-model \
+ -Winvalid-pch \
+ -Wjump-misses-init \
+ -Wlogical-op \
+ -Wmain \
+ -Wmaybe-uninitialized \
+ -Wmissing-braces \
+ -Wmissing-declarations \
+ -Wmissing-field-initializers \
+ -Wmissing-include-dirs \
+ -Wmissing-parameter-type \
+ -Wmissing-prototypes \
-Wmultichar \
- -Wnormalized=nfc \
+ -Wnarrowing \
+ -Wnested-externs \
+ -Wnonnull \
+ -Wold-style-declaration \
+ -Wold-style-definition \
+ -Wopenmp-simd \
-Woverflow \
+ -Woverlength-strings \
+ -Woverride-init \
+ -Wpacked \
+ -Wpacked-bitfield-compat \
+ -Wparentheses \
+ -Wpointer-arith \
+ -Wpointer-sign \
-Wpointer-to-int-cast \
-Wpragmas \
+ -Wreturn-local-addr \
+ -Wreturn-type \
+ -Wsequence-point \
+ -Wshadow \
+ -Wsizeof-pointer-memaccess \
+ -Wstack-protector \
+ -Wstrict-aliasing \
+ -Wstrict-overflow \
+ -Wstrict-prototypes \
-Wsuggest-attribute=const \
+ -Wsuggest-attribute=format \
-Wsuggest-attribute=noreturn \
-Wsuggest-attribute=pure \
+ -Wswitch \
+ -Wswitch-default \
+ -Wsync-nand \
+ -Wsystem-headers \
-Wtrampolines \
+ -Wtrigraphs \
+ -Wtype-limits \
+ -Wuninitialized \
+ -Wunknown-pragmas \
+ -Wunsafe-loop-optimizations \
+ -Wunused \
+ -Wunused-but-set-parameter \
+ -Wunused-but-set-variable \
+ -Wunused-function \
+ -Wunused-label \
+ -Wunused-local-typedefs \
+ -Wunused-macros \
+ -Wunused-parameter \
+ -Wunused-result \
+ -Wunused-value \
+ -Wunused-variable \
+ -Wvarargs \
+ -Wvariadic-macros \
+ -Wvector-operation-performance \
+ -Wvla \
+ -Wvolatile-register-var \
+ -Wwrite-strings \
+ \
; do
gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
done
- # Disable the missing-field-initializers warning if needed
+ # gcc --help=warnings outputs an unusual form for this option; list
+ # it here so that the above 'comm' command doesn't report a false match.
+ gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
+
+ # These are needed for older GCC versions.
+ if test -n "$GCC"; then
+ case `($CC --version) 2>/dev/null` in
+ 'gcc (GCC) '[[0-3]].* | \
+ 'gcc (GCC) '4.[[0-7]].*)
+ gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
+ gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
+ ;;
+ esac
+ fi
+
+ # Disable specific options as needed.
if test "$gl_cv_cc_nomfi_needed" = yes; then
gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
fi
+ if test "$gl_cv_cc_uninitialized_supported" = no; then
+ gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
+ fi
+
$1=$gl_manywarn_set
])
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index b1c4bd7..5081ab6 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -33,19 +33,96 @@ AC_DEFUN([LIBVIRT_GLIB_COMPILE_WARNINGS],[
dontwarn="$dontwarn -Wpadded"
# GCC very confused with -O2
dontwarn="$dontwarn -Wunreachable-code"
- # We explicitly need to remove const sometimes
+ # Too many to deal with
+ dontwarn="$dontwarn -Wconversion"
+ # Too many to deal with
+ dontwarn="$dontwarn -Wsign-conversion"
+ # GNULIB gettext.h violates
+ dontwarn="$dontwarn -Wvla"
+ # Many GNULIB header violations
+ dontwarn="$dontwarn -Wundef"
+ # Need to allow bad cast for execve()
dontwarn="$dontwarn -Wcast-qual"
- # Allow vars decl in the middle of blocks
- dontwarn="$dontwarn -Wdeclaration-after-statement"
- # Using long long is fine
+ # We need to use long long in many places
dontwarn="$dontwarn -Wlong-long"
- # Unused macros are ok
+ # We allow manual list of all enum cases without default:
+ dontwarn="$dontwarn -Wswitch-default"
+ # We allow optional default: instead of listing all enum values
+ dontwarn="$dontwarn -Wswitch-enum"
+ # Not a problem since we don't use -fstrict-overflow
+ dontwarn="$dontwarn -Wstrict-overflow"
+ # Not a problem since we don't use -funsafe-loop-optimizations
+ dontwarn="$dontwarn -Wunsafe-loop-optimizations"
+ # Things like virAsprintf mean we can't use this
+ dontwarn="$dontwarn -Wformat-nonliteral"
+ # Gnulib's stat-time.h violates this
+ dontwarn="$dontwarn -Waggregate-return"
+ # gcc 4.4.6 complains this is C++ only; gcc 4.7.0 implies this from -Wall
+ dontwarn="$dontwarn -Wenum-compare"
+
+ # gcc 4.2 treats attribute(format) as an implicit attribute(nonnull),
+ # which triggers spurious warnings for our usage
+ AC_CACHE_CHECK([whether the C compiler's -Wformat allows NULL strings],
+ [lv_cv_gcc_wformat_null_works], [
+ save_CFLAGS=$CFLAGS
+ CFLAGS='-Wunknown-pragmas -Werror -Wformat'
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include <stddef.h>
+ static __attribute__ ((__format__ (__printf__, 1, 2))) int
+ foo (const char *fmt, ...) { return !fmt; }
+ ]], [[
+ return foo(NULL);
+ ]])],
+ [lv_cv_gcc_wformat_null_works=yes],
+ [lv_cv_gcc_wformat_null_works=no])
+ CFLAGS=$save_CFLAGS])
+
+ # Gnulib uses '#pragma GCC diagnostic push' to silence some
+ # warnings, but older gcc doesn't support this.
+ AC_CACHE_CHECK([whether pragma GCC diagnostic push works],
+ [lv_cv_gcc_pragma_push_works], [
+ save_CFLAGS=$CFLAGS
+ CFLAGS='-Wunknown-pragmas -Werror'
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic pop
+ ]])],
+ [lv_cv_gcc_pragma_push_works=yes],
+ [lv_cv_gcc_pragma_push_works=no])
+ CFLAGS=$save_CFLAGS])
+ if test $lv_cv_gcc_pragma_push_works = no; then
+ dontwarn="$dontwarn -Wmissing-prototypes"
+ dontwarn="$dontwarn -Wmissing-declarations"
+ dontwarn="$dontwarn -Wcast-align"
+ else
+ AC_DEFINE_UNQUOTED([WORKING_PRAGMA_PUSH], 1,
+ [Define to 1 if gcc supports pragma push/pop])
+ fi
+
+ dnl Check whether strchr(s, char variable) causes a bogus compile
+ dnl warning, which is the case with GCC < 4.6 on some glibc
+ AC_CACHE_CHECK([whether the C compiler's -Wlogical-op gives bogus warnings],
+ [lv_cv_gcc_wlogical_op_broken], [
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="-O2 -Wlogical-op -Werror"
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+ #include <string.h>
+ ]], [[
+ const char *haystack;
+ char needle;
+ return strchr(haystack, needle) == haystack;]])],
+ [lv_cv_gcc_wlogical_op_broken=no],
+ [lv_cv_gcc_wlogical_op_broken=yes])
+ CFLAGS="$save_CFLAGS"])
+
+ # We might fundamentally need some of these disabled forever, but
+ # ideally we'd turn many of them on
+ dontwarn="$dontwarn -Wfloat-equal"
+ dontwarn="$dontwarn -Wdeclaration-after-statement"
+ dontwarn="$dontwarn -Wpacked"
dontwarn="$dontwarn -Wunused-macros"
-
-
- # g_clear_object & G_ATOMIC_OP_USE_GCC_BUILTINS causes
- # violations with this. XXX Fix glib ?
- dontwarn="$dontwarn -Wbad-function-cast"
+ dontwarn="$dontwarn -Woverlength-strings"
+ dontwarn="$dontwarn -Wstack-protector"
# Get all possible GCC warnings
gl_MANYWARN_ALL_GCC([maybewarn])
@@ -53,78 +130,105 @@ AC_DEFUN([LIBVIRT_GLIB_COMPILE_WARNINGS],[
# Remove the ones we don't want, blacklisted earlier
gl_MANYWARN_COMPLEMENT([wantwarn], [$maybewarn], [$dontwarn])
- # Check for $CC support of each warning
- for w in $wantwarn; do
- gl_WARN_ADD([$w])
- done
-
# GNULIB uses '-W' (aka -Wextra) which includes a bunch of stuff.
# Unfortunately, this means you can't simply use '-Wsign-compare'
# with gl_MANYWARN_COMPLEMENT
# So we have -W enabled, and then have to explicitly turn off...
- gl_WARN_ADD([-Wno-sign-compare])
-
- # Due to gutils.h bug in g_bit_storage
- gl_WARN_ADD([-Wno-sign-conversion])
- gl_WARN_ADD([-Wno-conversion])
- gl_WARN_ADD([-Wno-unused-parameter])
- # We can't enable this due to horrible spice_usb_device_get_description
- # signature
- gl_WARN_ADD([-Wno-format-nonliteral])
-
-
+ wantwarn="$wantwarn -Wno-sign-compare"
# GNULIB expects this to be part of -Wc++-compat, but we turn
# that one off, so we need to manually enable this again
- gl_WARN_ADD([-Wjump-misses-init])
+ wantwarn="$wantwarn -Wjump-misses-init"
+
+ # GNULIB turns on -Wformat=2 which implies -Wformat-nonliteral,
+ # so we need to manually re-exclude it. Also, older gcc 4.2
+ # added an implied ATTRIBUTE_NONNULL on any parameter marked
+ # ATTRIBUTE_FMT_PRINT, which causes -Wformat failure on our
+ # intentional use of virReportError(code, NULL).
+ wantwarn="$wantwarn -Wno-format-nonliteral"
+ if test $lv_cv_gcc_wformat_null_works = no; then
+ wantwarn="$wantwarn -Wno-format"
+ fi
# This should be < 256 really. Currently we're down to 4096,
# but using 1024 bytes sized buffers (mostly for virStrerror)
# stops us from going down further
- gl_WARN_ADD([-Wframe-larger-than=4096])
-
- # Use improved glibc headers
- AH_VERBATIM([FORTIFY_SOURCE],
- [/* Enable compile-time and run-time bounds-checking, and some warnings,
- without upsetting newer glibc. */
- #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ &&
__OPTIMIZE__
- # define _FORTIFY_SOURCE 2
- #endif
- ])
+ wantwarn="$wantwarn -Wframe-larger-than=4096"
+ dnl wantwarn="$wantwarn -Wframe-larger-than=256"
# Extra special flags
dnl -fstack-protector stuff passes gl_WARN_ADD with gcc
dnl on Mingw32, but fails when actually used
case $host in
+ aarch64-*-*)
+ dnl "error: -fstack-protector not supported for this target [-Werror]"
+ ;;
*-*-linux*)
- dnl Fedora only uses -fstack-protector, but doesn't seem to
- dnl be great overhead in adding -fstack-protector-all instead
- dnl gl_WARN_ADD([-fstack-protector])
- gl_WARN_ADD([-fstack-protector-all])
- gl_WARN_ADD([--param=ssp-buffer-size=4])
+ dnl Prefer -fstack-protector-strong if it's available.
+ dnl There doesn't seem to be great overhead in adding
+ dnl -fstack-protector-all instead of -fstack-protector.
+ dnl
+ dnl We also don't need ssp-buffer-size with -all or -strong,
+ dnl since functions are protected regardless of buffer size.
+ dnl wantwarn="$wantwarn --param=ssp-buffer-size=4"
+ wantwarn="$wantwarn -fstack-protector-strong"
+ ;;
+ *-*-freebsd*)
+ dnl FreeBSD ships old gcc 4.2.1 which doesn't handle
+ dnl -fstack-protector-all well
+ wantwarn="$wantwarn -fstack-protector"
+
+ wantwarn="$wantwarn -Wno-unused-command-line-argument"
;;
esac
- gl_WARN_ADD([-fexceptions])
- gl_WARN_ADD([-fasynchronous-unwind-tables])
- gl_WARN_ADD([-fdiagnostics-show-option])
- gl_WARN_ADD([-funit-at-a-time])
+ wantwarn="$wantwarn -fexceptions"
+ wantwarn="$wantwarn -fasynchronous-unwind-tables"
# Need -fipa-pure-const in order to make -Wsuggest-attribute=pure
# fire even without -O.
- gl_WARN_ADD([-fipa-pure-const])
-
+ wantwarn="$wantwarn -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])
-
+ wantwarn="$wantwarn -Wno-suggest-attribute=pure"
+ wantwarn="$wantwarn -Wno-suggest-attribute=const"
if test "$set_werror" = "yes"
then
- gl_WARN_ADD([-Werror])
+ wantwarn="$wantwarn -Werror"
fi
- WARN_LDFLAGS=$WARN_CFLAGS
- AC_SUBST([WARN_CFLAGS])
- AC_SUBST([WARN_LDFLAGS])
+ # Check for $CC support of each warning
+ for w in $wantwarn; do
+ gl_WARN_ADD([$w])
+ done
+
+ case $host in
+ *-*-linux*)
+ dnl Fall back to -fstack-protector-all if -strong is not available
+ case $WARN_CFLAGS in
+ *-fstack-protector-strong*)
+ ;;
+ *)
+ gl_WARN_ADD(["-fstack-protector-all"])
+ ;;
+ esac
+ ;;
+ esac
+
+ # Silence certain warnings in gnulib, and use improved glibc headers
+ AC_DEFINE([lint], [1],
+ [Define to 1 if the compiler is checking for lint.])
+ AH_VERBATIM([FORTIFY_SOURCE],
+ [/* Enable compile-time and run-time bounds-checking, and some warnings,
+ without upsetting newer glibc. */
+ #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ &&
__OPTIMIZE__
+ # define _FORTIFY_SOURCE 2
+ #endif
+ ])
+
+ if test "$gl_cv_warn_c__Wlogical_op" = yes &&
+ test "$lv_cv_gcc_wlogical_op_broken" = yes; then
+ AC_DEFINE_UNQUOTED([BROKEN_GCC_WLOGICALOP], 1,
+ [Define to 1 if gcc -Wlogical-op reports false positives on strchr])
+ fi
])
diff --git a/m4/warnings.m4 b/m4/warnings.m4
index e3d239b..43156f4 100644
--- a/m4/warnings.m4
+++ b/m4/warnings.m4
@@ -1,5 +1,5 @@
# warnings.m4 serial 11
-dnl Copyright (C) 2008-2013 Free Software Foundation, Inc.
+dnl Copyright (C) 2008-2014 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
--
2.0.4
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list