Martin Kletzander
2021-May-07 13:23 UTC
[Libguestfs] [libnbd PATCH 3/5] libev: Check for old compiler
On Fri, May 07, 2021 at 07:14:32AM -0500, Eric Blake wrote:>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? >This is one of the results that I was not sure about. We could just add no-strict-aliasing for that one particular example of course. I figured it is just an example and it only causes an issue on CentOS 7, OpenSUSE Leap 15.2, Ubuntu 18.04 and some similarly old systems if I remember correctly. But changing the LIBEV_CFLAGS seems more fit for the purpose.>-- >Eric Blake, Principal Software Engineer >Red Hat, Inc. +1-919-301-3226 >Virtualization: qemu.org | libvirt.org >-------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://listman.redhat.com/archives/libguestfs/attachments/20210507/3b85bf33/attachment.sig>
Eric Blake
2021-May-07 13:41 UTC
[Libguestfs] [libnbd PATCH 3/5] libev: Check for old compiler
On 5/7/21 8:23 AM, Martin Kletzander wrote:>>> +??? 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? >> > > This is one of the results that I was not sure about.? We could just add > no-strict-aliasing for that one particular example of course.? I figured > it is just an example and it only causes an issue on CentOS 7, OpenSUSE > Leap 15.2, Ubuntu 18.04 and some similarly old systems if I remember > correctly.? But changing the LIBEV_CFLAGS seems more fit for the purpose.Sounds even better! -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Nir Soffer
2021-May-09 21:03 UTC
[Libguestfs] [libnbd PATCH 3/5] libev: Check for old compiler
On Fri, May 7, 2021 at 4:24 PM Martin Kletzander <mkletzan at redhat.com> wrote:> > On Fri, May 07, 2021 at 07:14:32AM -0500, Eric Blake wrote: > >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? > > > > This is one of the results that I was not sure about. We could just add > no-strict-aliasing for that one particular example of course. I figured > it is just an example and it only causes an issue on CentOS 7, OpenSUSE > Leap 15.2, Ubuntu 18.04 and some similarly old systems if I remember > correctly.Do we really support Centos 7? libnbd is available since rhel 8 (2, 3?). Why support older systems? Time spent on older systems means less time working features, performance, support for new systems, etc.> But changing the LIBEV_CFLAGS seems more fit for the purpose.Sounds like the best option. Nir