Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
config.h | 7 +
configure.ac | 3 -
m4/virt-compile-warnings.m4 | 255 ------------------------------------
m4/virt-warnings.m4 | 115 ----------------
meson.build | 221 ++++++++++++++++++++++++++++---
5 files changed, 211 insertions(+), 390 deletions(-)
delete mode 100644 m4/virt-compile-warnings.m4
delete mode 100644 m4/virt-warnings.m4
diff --git a/config.h b/config.h
index 9c433ad4c0f..368688f3d01 100644
--- a/config.h
+++ b/config.h
@@ -1,5 +1,12 @@
#include <meson-config.h>
+/* 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
+
#ifndef __GNUC__
# error "Libvirt requires GCC >= 4.8, or CLang"
#endif
diff --git a/configure.ac b/configure.ac
index 8f16b364de6..56a471fc3ab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -161,7 +161,6 @@ fi
# Check for compiler and library settings.
-LIBVIRT_COMPILE_WARNINGS
LIBVIRT_LINKER_RELRO
LIBVIRT_LINKER_NO_INDIRECT
LIBVIRT_LINKER_NO_UNDEFINED
@@ -849,8 +848,6 @@ AC_MSG_NOTICE([])
AC_MSG_NOTICE([Miscellaneous])
AC_MSG_NOTICE([])
LIBVIRT_RESULT_DEBUG
-LIBVIRT_RESULT([Use -Werror], [$enable_werror])
-LIBVIRT_RESULT([Warning Flags], [$WARN_CFLAGS])
LIBVIRT_RESULT_DTRACE
LIBVIRT_RESULT_NUMAD
LIBVIRT_RESULT_INIT_SCRIPT
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
deleted file mode 100644
index d3538d59f82..00000000000
--- a/m4/virt-compile-warnings.m4
+++ /dev/null
@@ -1,255 +0,0 @@
-dnl
-dnl Enable all known GCC compiler warnings, except for those
-dnl we can't yet cope with
-dnl
-AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
- dnl ******************************
- dnl More compiler warnings
- dnl ******************************
-
- LIBVIRT_ARG_ENABLE([WERROR], [Use -Werror (if supported)], [check])
- if test "$enable_werror" = "check"; then
- if test -d $srcdir/.git; then
- is_git_version=true
- enable_werror=yes
- else
- enable_werror=no
- fi
- fi
-
- # List of warnings that are not relevant / wanted
-
- # Don't care about C++ compiler compat
- dontwarn="$dontwarn -Wc++-compat"
- dontwarn="$dontwarn -Wabi"
- dontwarn="$dontwarn -Wdeprecated"
- # Don't care about ancient C standard compat
- dontwarn="$dontwarn -Wtraditional"
- # Don't care about ancient C standard compat
- dontwarn="$dontwarn -Wtraditional-conversion"
- # Ignore warnings in /usr/include
- dontwarn="$dontwarn -Wsystem-headers"
- # Happy for compiler to add struct padding
- dontwarn="$dontwarn -Wpadded"
- # GCC very confused with -O2
- dontwarn="$dontwarn -Wunreachable-code"
- # Too many to deal with
- dontwarn="$dontwarn -Wconversion"
- # Too many to deal with
- dontwarn="$dontwarn -Wsign-conversion"
- # Need to allow bad cast for execve()
- dontwarn="$dontwarn -Wcast-qual"
- # We need to use long long in many places
- dontwarn="$dontwarn -Wlong-long"
- # We allow manual list of all enum cases without default:
- dontwarn="$dontwarn -Wswitch-default"
- # 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"
- # gcc 4.4.6 complains this is C++ only; gcc 4.7.0 implies this from -Wall
- dontwarn="$dontwarn -Wenum-compare"
- # gcc 5.1 -Wformat-signedness mishandles enums, not ready for prime time
- dontwarn="$dontwarn -Wformat-signedness"
- # Several conditionals expand the same on both branches
- # depending on the particular platform/architecture
- dontwarn="$dontwarn -Wduplicated-branches"
- # > This warning does not generally indicate that there is anything wrong
- # > with your code; it merely indicates that GCC's optimizers are unable
- # > to handle the code effectively.
- # Source:
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
- dontwarn="$dontwarn -Wdisabled-optimization"
- # Various valid glib APIs/macros trigger this warning
- dontwarn="$dontwarn -Wbad-function-cast"
-
- # Broken in 6.0 and later
- #
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602
- AC_CACHE_CHECK([whether gcc gives bogus warnings for -Wlogical-op],
- [lv_cv_gcc_wlogical_op_equal_expr_broken], [
- save_CFLAGS="$CFLAGS"
- CFLAGS="-O2 -Wlogical-op -Werror"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
- #define TEST1 1
- #define TEST2 TEST1
- ]], [[
- int test = 0;
- return test == TEST1 || test == TEST2;]])],
- [lv_cv_gcc_wlogical_op_equal_expr_broken=no],
- [lv_cv_gcc_wlogical_op_equal_expr_broken=yes])
- CFLAGS="$save_CFLAGS"])
-
- AC_CACHE_CHECK([whether clang gives bogus warnings for -Wdouble-promotion],
- [lv_cv_clang_double_promotion_broken], [
- save_CFLAGS="$CFLAGS"
- CFLAGS="-O2 -Wdouble-promotion -Werror"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
- #include <math.h>
- ]], [[
- float f = 0.0;
- return isnan(f);]])],
- [lv_cv_clang_double_promotion_broken=no],
- [lv_cv_clang_double_promotion_broken=yes])
- CFLAGS="$save_CFLAGS"])
-
- if test "$lv_cv_clang_double_promotion_broken" = "yes";
- then
- dontwarn="$dontwarn -Wdouble-promotion"
- fi
-
- # Clang complains about unused static inline functions
- # which are common with G_DEFINE_AUTOPTR_CLEANUP_FUNC
- AC_CACHE_CHECK([whether clang gives bogus warnings for -Wunused-function],
- [lv_cv_clang_unused_function_broken], [
- save_CFLAGS="$CFLAGS"
- CFLAGS="-Wunused-function -Werror"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
- static inline void foo(void) {}
- ]], [[
- return 0]])],
- [lv_cv_clang_unused_function_broken=no],
- [lv_cv_clang_unused_function_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"
- dontwarn="$dontwarn -Woverlength-strings"
- dontwarn="$dontwarn -Wstack-protector"
- dontwarn="$dontwarn -Wsuggest-attribute=malloc"
-
- # Get all possible GCC warnings
- gl_MANYWARN_ALL_GCC([maybewarn])
-
- # Remove the ones we don't want, blacklisted earlier
- gl_MANYWARN_COMPLEMENT([wantwarn], [$maybewarn], [$dontwarn])
-
- # -Wunused-functin is implied by -Wall we must turn it
- # off explicitly.
- if test "$lv_cv_clang_unused_function_broken" = "yes";
- then
- wantwarn="$wantwarn -Wno-unused-function"
- fi
-
- # manywarnings 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...
- wantwarn="$wantwarn -Wno-sign-compare"
- # We do "bad" function casts all the time for event callbacks
- wantwarn="$wantwarn -Wno-cast-function-type"
-
- # CLang incorrectly complains about dup typedefs win gnu99 mode
- # so use this CLang-specific arg to keep it quiet
- wantwarn="$wantwarn -Wno-typedef-redefinition"
-
- # manywarnings expects this to be part of -Wc++-compat, but we turn
- # that one off, so we need to manually enable this again
- wantwarn="$wantwarn -Wjump-misses-init"
-
- # manywarnings explicitly filters it out, preferring -Wswitch
- # but that doesn't report missing enums if a default:
- # is present.
- wantwarn="$wantwarn -Wswitch-enum"
-
- # manywarnings turns on -Wformat=2 which implies -Wformat-nonliteral,
- # so we need to manually re-exclude it.
- wantwarn="$wantwarn -Wno-format-nonliteral"
-
- # -Wformat enables this by default, and we should keep it,
- # but need to rewrite various areas of code first
- wantwarn="$wantwarn -Wno-format-truncation"
-
- # 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
- wantwarn="$wantwarn -Wframe-larger-than=4096"
- gl_WARN_ADD([-Wframe-larger-than=262144], [RELAXED_FRAME_LIMIT_CFLAGS])
-
- # 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 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
- wantwarn="$wantwarn -fexceptions"
- wantwarn="$wantwarn -fasynchronous-unwind-tables"
-
- # Need -fipa-pure-const in order to make -Wsuggest-attribute=pure
- # fire even without -O.
- wantwarn="$wantwarn -fipa-pure-const"
- # We should eventually enable this, but right now there are at
- # least 75 functions triggering warnings.
- wantwarn="$wantwarn -Wno-suggest-attribute=pure"
- wantwarn="$wantwarn -Wno-suggest-attribute=const"
-
- if test "$enable_werror" = "yes"
- then
- wantwarn="$wantwarn -Werror"
- fi
-
- # Request the gnu99 standard which is the best choice with
- # gcc 4.8.0. Not a warning flag, but the probing mechanism
- # is convenient
- wantwarn="$wantwarn -std=gnu99"
-
- # 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
-
- case $WARN_CFLAGS in
- *-Wsuggest-attribute=format*)
- AC_DEFINE([HAVE_SUGGEST_ATTRIBUTE_FORMAT], [1], [Whether
-Wsuggest-attribute=format works])
- ;;
- esac
-
- # Use security checked 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
- ])
-
- if test "$gl_cv_warn_c__Wlogical_op" = yes &&
- test "$lv_cv_gcc_wlogical_op_equal_expr_broken" = yes; then
- AC_DEFINE_UNQUOTED([BROKEN_GCC_WLOGICALOP_EQUAL_EXPR], 1,
- [Define to 1 if gcc -Wlogical-op reports false positive 'or' equal
expr])
- fi
-])
diff --git a/m4/virt-warnings.m4 b/m4/virt-warnings.m4
deleted file mode 100644
index d272365f0a1..00000000000
--- a/m4/virt-warnings.m4
+++ /dev/null
@@ -1,115 +0,0 @@
-# warnings.m4 serial 14
-dnl Copyright (C) 2008-2020 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.
-
-dnl From Simon Josefsson
-
-# gl_AS_VAR_APPEND(VAR, VALUE)
-# ----------------------------
-# Provide the functionality of AS_VAR_APPEND if Autoconf does not have it.
-m4_ifdef([AS_VAR_APPEND],
-[m4_copy([AS_VAR_APPEND], [gl_AS_VAR_APPEND])],
-[m4_define([gl_AS_VAR_APPEND],
-[AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])])
-
-
-# gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED],
-# [PROGRAM = AC_LANG_PROGRAM()])
-# -----------------------------------------------------------------
-# Check if the compiler supports OPTION when compiling PROGRAM.
-#
-# The effects of this macro depend on the current language (_AC_LANG).
-AC_DEFUN([gl_COMPILER_OPTION_IF],
-[
-dnl FIXME: gl_Warn must be used unquoted until we can assume Autoconf
-dnl 2.64 or newer.
-AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl
-AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl
-AS_LITERAL_IF([$1],
- [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))],
- [gl_positive="$1"
-case $gl_positive in
- -Wno-*) gl_positive=-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;;
-esac
-m4_pushdef([gl_Positive], [$gl_positive])])dnl
-AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([gl_Warn]), [
- gl_save_compiler_FLAGS="$gl_Flags"
- gl_AS_VAR_APPEND(m4_defn([gl_Flags]),
- [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["])
- AC_LINK_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([])])],
- [AS_VAR_SET(gl_Warn, [yes])],
- [AS_VAR_SET(gl_Warn, [no])])
- gl_Flags="$gl_save_compiler_FLAGS"
-])
-AS_VAR_IF(gl_Warn, [yes], [$2], [$3])
-m4_popdef([gl_Positive])dnl
-AS_VAR_POPDEF([gl_Flags])dnl
-AS_VAR_POPDEF([gl_Warn])dnl
-])
-
-# gl_UNKNOWN_WARNINGS_ARE_ERRORS
-# ------------------------------
-# Clang doesn't complain about unknown warning options unless one also
-# specifies -Wunknown-warning-option -Werror. Detect this.
-#
-# The effects of this macro depend on the current language (_AC_LANG).
-AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS],
-[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
-
-# Specialization for _AC_LANG = C. This macro can be AC_REQUIREd.
-# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
-m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C)],
-[
- AC_LANG_PUSH([C])
- gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
- AC_LANG_POP([C])
-])
-
-# Specialization for _AC_LANG = C++. This macro can be AC_REQUIREd.
-# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
-m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C++)],
-[
- AC_LANG_PUSH([C++])
- gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
- AC_LANG_POP([C++])
-])
-
-# Specialization for _AC_LANG = Objective C. This macro can be AC_REQUIREd.
-# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
-m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(Objective C)],
-[
- AC_LANG_PUSH([Objective C])
- gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
- AC_LANG_POP([Objective C])
-])
-
-AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL],
-[gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option],
- [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'],
- [gl_unknown_warnings_are_errors=])])
-
-# gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS],
-# [PROGRAM = AC_LANG_PROGRAM()])
-# -----------------------------------------------------------
-# Adds parameter to WARN_CFLAGS/WARN_CXXFLAGS if the compiler supports it
-# when compiling PROGRAM. For example, gl_WARN_ADD([-Wparentheses]).
-#
-# If VARIABLE is a variable name, AC_SUBST it.
-#
-# The effects of this macro depend on the current language (_AC_LANG).
-AC_DEFUN([gl_WARN_ADD],
-[AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS(]_AC_LANG[)])
-gl_COMPILER_OPTION_IF([$1],
- [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$2]]), ["
$1"])],
- [],
- [$3])
-m4_ifval([$2],
- [AS_LITERAL_IF([$2], [AC_SUBST([$2])])],
- [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl
-])
-
-# Local Variables:
-# mode: autoconf
-# End:
diff --git a/meson.build b/meson.build
index d9a95e049c0..2450a8bdd79 100644
--- a/meson.build
+++ b/meson.build
@@ -7,6 +7,7 @@ project(
'buildtype=debugoptimized',
'b_pie=true',
'c_std=gnu99',
+ 'warning_level=2',
],
)
@@ -212,10 +213,8 @@ cc_flags = [
'-Waddress',
'-Waddress-of-packed-member',
'-Waggressive-loop-optimizations',
- '-Wall',
'-Wattribute-warning',
'-Wattributes',
- '-Wbad-function-cast',
'-Wbool-compare',
'-Wbool-operation',
'-Wbuiltin-declaration-mismatch',
@@ -232,27 +231,20 @@ cc_flags = [
'-Wcpp',
'-Wdangling-else',
'-Wdate-time',
- '-Wdeprecated',
'-Wdeprecated-declarations',
'-Wdesignated-init',
- '-Wdisabled-optimization',
'-Wdiscarded-array-qualifiers',
'-Wdiscarded-qualifiers',
'-Wdiv-by-zero',
- '-Wdouble-promotion',
- '-Wduplicated-branches',
'-Wduplicated-cond',
'-Wduplicate-decl-specifier',
'-Wempty-body',
'-Wendif-labels',
- '-Wenum-compare',
'-Wexpansion-to-defined',
- '-Wextra',
'-Wformat-contains-nul',
'-Wformat-extra-args',
'-Wformat-nonliteral',
'-Wformat-security',
- '-Wformat-signedness',
'-Wformat-y2k',
'-Wformat-zero-length',
'-Wframe-address',
@@ -299,9 +291,7 @@ cc_flags = [
'-Wold-style-definition',
'-Wopenmp-simd',
'-Woverflow',
- '-Woverlength-strings',
'-Woverride-init',
- '-Wpacked',
'-Wpacked-bitfield-compat',
'-Wpacked-not-aligned',
'-Wparentheses',
@@ -323,15 +313,12 @@ cc_flags = [
'-Wsizeof-array-argument',
'-Wsizeof-pointer-div',
'-Wsizeof-pointer-memaccess',
- '-Wstack-protector',
'-Wstrict-aliasing',
- '-Wstrict-overflow',
'-Wstrict-prototypes',
'-Wstringop-truncation',
'-Wsuggest-attribute=cold',
'-Wsuggest-attribute=const',
'-Wsuggest-attribute=format',
- '-Wsuggest-attribute=malloc',
'-Wsuggest-attribute=noreturn',
'-Wsuggest-attribute=pure',
'-Wsuggest-final-methods',
@@ -340,21 +327,18 @@ cc_flags = [
'-Wswitch-bool',
'-Wswitch-unreachable',
'-Wsync-nand',
- '-Wsystem-headers',
'-Wtautological-compare',
'-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',
@@ -392,6 +376,203 @@ cc_flags += [
'-Wvla-larger-then=4031',
]
+cc_flags += [
+ # So we have -W enabled, and then have to explicitly turn off...
+ '-Wno-sign-compare',
+
+ # We do "bad" function casts all the time for event callbacks
+ '-Wno-cast-function-type',
+
+ # CLang incorrectly complains about dup typedefs win gnu99 mode
+ # so use this CLang-specific arg to keep it quiet
+ '-Wno-typedef-redefinition',
+
+ # We don't use -Wc++-compat so we have to enable it explicitly
+ '-Wjump-misses-init',
+
+ # TODO comment
+ '-Wswitch-enum',
+
+ # -Wformat=2 implies -Wformat-nonliteral so we need to manually exclude it
+ '-Wno-format-nonliteral',
+
+ # -Wformat enables this by default, and we should keep it,
+ # but need to rewrite various areas of code first
+ '-Wno-format-truncation',
+
+ # 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
+ '-Wframe-larger-than=4096',
+
+ # extra special flags
+ '-fexceptions',
+ '-fasynchronous-unwind-tables',
+
+ # Need -fipa-pure-const in order to make -Wsuggest-attribute=pure
+ # fire even without -O.
+ '-fipa-pure-const',
+
+ # We should eventually enable this, but right now there are at
+ # least 75 functions triggering warnings.
+ '-Wno-suggest-attribute=pure',
+ '-Wno-suggest-attribute=const',
+]
+
+if git
+ cc_flags += [ '-Werror' ]
+endif
This doesn't seem right. We definitely don't want this to be based
solely on whether we're building from git.