Martin Kletzander
2021-May-06 11:30 UTC
[Libguestfs] [libnbd PATCH 3/5] libev: Check for old compiler
At some point GCC added some optimisations and checks that started emitting warnings on harmless code: ...dereferencing type-punned pointer will break strict-aliasing rules... This was later fixed, but can still break the build (or report warnings) on old GCCs (e.g. 7.5.0) when building the libev example. Signed-off-by: Martin Kletzander <mkletzan at redhat.com> --- configure.ac | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/configure.ac b/configure.ac index 19b7bfdb5d2a..3b51354346cc 100644 --- a/configure.ac +++ b/configure.ac @@ -247,6 +247,30 @@ PKG_CHECK_MODULES([LIBEV], [libev], [ AC_MSG_WARN([ev.h not found, some examples will not be compiled]) ]) ]) + +AS_IF([test "x$LIBEV_LIBS" != "x"], [ + old_CFLAGS="$CFLAGS" + CFLAGS="-Werror=strict-aliasing -O2" + AC_MSG_CHECKING([if the compiler is new enough for good aliasing rules]) + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ + #include <ev.h> + + static void cb (struct ev_loop *l, ev_timer *t, int e) { } + static ev_timer timer; + ], [ + ev_timer_init (&timer, cb, 0, .1); + ]) + ], [ + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + AC_SUBST([LIBEV_CFLAGS], [""]) + AC_SUBST([LIBEV_LIBS], [""]) + AC_MSG_WARN([compiler is probably too old to compile with libev without errors, some examples will not be compiled]) + ]) + CFLAGS="$old_CFLAGS" +]) AM_CONDITIONAL([HAVE_LIBEV], [test "x$LIBEV_LIBS" != "x"]) dnl FUSE 3 is optional to build the nbdfuse program. -- 2.31.1
Eric Blake
2021-May-07 12:14 UTC
[Libguestfs] [libnbd PATCH 3/5] libev: Check for old compiler
On 5/6/21 6:30 AM, Martin Kletzander wrote:> At some point GCC added some optimisations and checks that started emitting > warnings on harmless code: > > ...dereferencing type-punned pointer will break strict-aliasing rules... > > This was later fixed, but can still break the build (or report warnings) on old > GCCs (e.g. 7.5.0) when building the libev example. > > Signed-off-by: Martin Kletzander <mkletzan at redhat.com> > --- > configure.ac | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/configure.ac b/configure.ac > index 19b7bfdb5d2a..3b51354346cc 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -247,6 +247,30 @@ PKG_CHECK_MODULES([LIBEV], [libev], [ > AC_MSG_WARN([ev.h not found, some examples will not be compiled]) > ]) > ]) > + > +AS_IF([test "x$LIBEV_LIBS" != "x"], [ > + old_CFLAGS="$CFLAGS" > + CFLAGS="-Werror=strict-aliasing -O2" > + AC_MSG_CHECKING([if the compiler is new enough for good aliasing rules]) > + AC_COMPILE_IFELSE([ > + AC_LANG_PROGRAM([ > + #include <ev.h> > + > + static void cb (struct ev_loop *l, ev_timer *t, int e) { } > + static ev_timer timer; > + ], [ > + ev_timer_init (&timer, cb, 0, .1); > + ]) > + ], [ > + AC_MSG_RESULT([yes]) > + ], [ > + AC_MSG_RESULT([no]) > + AC_SUBST([LIBEV_CFLAGS], [""]) > + AC_SUBST([LIBEV_LIBS], [""]) > + AC_MSG_WARN([compiler is probably too old to compile with libev without errors, some examples will not be compiled])Do we really need to skip compiling the example altogether, or can we just modify CFLAGS to add -Wno-strict-aliasing to prevent the failure? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Richard W.M. Jones
2021-May-11 11:21 UTC
[Libguestfs] [libnbd PATCH 3/5] libev: Check for old compiler
Patch already discussed extensively. I'm happy with what seems to have been decided (adding -Wno-strict-aliasing I think). Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v