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
Martin Kletzander
2021-May-12 13:58 UTC
[Libguestfs] [libnbd PATCH 3/5] libev: Check for old compiler
On Mon, May 10, 2021 at 12:03:36AM +0300, Nir Soffer wrote:>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? >Strictly speaking I do not think there is any description of what is supported for libnbd. I just wanted as much as possible to start with, but centos7 is now already out.>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. >I did that, we can remove it later.>Nir >-------------- 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/20210512/a02edd6a/attachment.sig>