diff mbox series

[v2,01/13] compiler.h: replace QEMU_GNUC_PREREQ macro

Message ID 20201126112915.525285-2-marcandre.lureau@redhat.com
State New
Headers show
Series Remove GCC < 4.8 checks | expand

Commit Message

Marc-André Lureau Nov. 26, 2020, 11:29 a.m. UTC
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Replace it with glib G_GNUC_CHECK_VERSION.

Available since 2.42, the macro received a small correction in
2.55.1 (glib d44afbadda8a "macros: make G_GNUC_CHECK_VERSION()
portable" which was apparently harmless).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qemu/atomic.h      |  2 +-
 include/qemu/compiler.h    | 15 +++------------
 scripts/cocci-macro-file.h |  1 -
 accel/tcg/cpu-exec.c       |  2 +-
 4 files changed, 5 insertions(+), 15 deletions(-)

Comments

Peter Maydell Nov. 26, 2020, 11:48 a.m. UTC | #1
On Thu, 26 Nov 2020 at 11:29, <marcandre.lureau@redhat.com> wrote:
>
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> Replace it with glib G_GNUC_CHECK_VERSION.
>
> Available since 2.42, the macro received a small correction in
> 2.55.1 (glib d44afbadda8a "macros: make G_GNUC_CHECK_VERSION()
> portable" which was apparently harmless).
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  include/qemu/atomic.h      |  2 +-
>  include/qemu/compiler.h    | 15 +++------------
>  scripts/cocci-macro-file.h |  1 -
>  accel/tcg/cpu-exec.c       |  2 +-
>  4 files changed, 5 insertions(+), 15 deletions(-)
>
> diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h
> index c1d211a351..c409257c11 100644
> --- a/include/qemu/atomic.h
> +++ b/include/qemu/atomic.h
> @@ -248,7 +248,7 @@
>   * 4.3 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36793).
>   */
>  #if defined(__i386__) || defined(__x86_64__)
> -#if !QEMU_GNUC_PREREQ(4, 4)
> +#if !G_GNUC_CHECK_VERSION(4, 4)
>  #if defined __x86_64__
>  #define smp_mb()    ({ asm volatile("mfence" ::: "memory"); (void)0; })
>  #else
> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
> index c76281f354..cf044bab4a 100644
> --- a/include/qemu/compiler.h
> +++ b/include/qemu/compiler.h
> @@ -7,21 +7,12 @@
>  #ifndef COMPILER_H
>  #define COMPILER_H
>
> +#include "glib-compat.h"

osdep.h already includes glib-compat.h, so if it's safe to
include it this early we should just move that #include line
in osdep.h up above compiler.h. But I don't think it's going
to be quite that simple, because some parts of osdep.h
need to happen before we include any system headers, and
glib-compat.h includes some system headers. As it stands
this fragment will pull in glib-compat.h too early.

You probably need to rearrange osdep.h so it is
 * config-host.h
 * poison.h
 * bits that must go before any standard headers
 * pure system includes
 * glib-compat.h
 * compiler.h
(and hopefully none of the above needed stuff set up by compiler.h !)

Or if this tangle of bits depending on each other seems too
messy, we could just leave QEMU_GNUC_PREREQ the way it is :-)

thanks
-- PMM
Marc-André Lureau Nov. 26, 2020, 11:55 a.m. UTC | #2
Hi

On Thu, Nov 26, 2020 at 3:48 PM Peter Maydell <peter.maydell@linaro.org> wrote:
>
> On Thu, 26 Nov 2020 at 11:29, <marcandre.lureau@redhat.com> wrote:
> >
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > Replace it with glib G_GNUC_CHECK_VERSION.
> >
> > Available since 2.42, the macro received a small correction in
> > 2.55.1 (glib d44afbadda8a "macros: make G_GNUC_CHECK_VERSION()
> > portable" which was apparently harmless).
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  include/qemu/atomic.h      |  2 +-
> >  include/qemu/compiler.h    | 15 +++------------
> >  scripts/cocci-macro-file.h |  1 -
> >  accel/tcg/cpu-exec.c       |  2 +-
> >  4 files changed, 5 insertions(+), 15 deletions(-)
> >
> > diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h
> > index c1d211a351..c409257c11 100644
> > --- a/include/qemu/atomic.h
> > +++ b/include/qemu/atomic.h
> > @@ -248,7 +248,7 @@
> >   * 4.3 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36793).
> >   */
> >  #if defined(__i386__) || defined(__x86_64__)
> > -#if !QEMU_GNUC_PREREQ(4, 4)
> > +#if !G_GNUC_CHECK_VERSION(4, 4)
> >  #if defined __x86_64__
> >  #define smp_mb()    ({ asm volatile("mfence" ::: "memory"); (void)0; })
> >  #else
> > diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
> > index c76281f354..cf044bab4a 100644
> > --- a/include/qemu/compiler.h
> > +++ b/include/qemu/compiler.h
> > @@ -7,21 +7,12 @@
> >  #ifndef COMPILER_H
> >  #define COMPILER_H
> >
> > +#include "glib-compat.h"
>
> osdep.h already includes glib-compat.h, so if it's safe to
> include it this early we should just move that #include line
> in osdep.h up above compiler.h. But I don't think it's going
> to be quite that simple, because some parts of osdep.h
> need to happen before we include any system headers, and
> glib-compat.h includes some system headers. As it stands
> this fragment will pull in glib-compat.h too early.
>
> You probably need to rearrange osdep.h so it is
>  * config-host.h
>  * poison.h
>  * bits that must go before any standard headers
>  * pure system includes
>  * glib-compat.h
>  * compiler.h
> (and hopefully none of the above needed stuff set up by compiler.h !)
>
> Or if this tangle of bits depending on each other seems too
> messy, we could just leave QEMU_GNUC_PREREQ the way it is :-)

Or I just change the order the header are included in libvhost-user
(before https://patchew.org/QEMU/20201125100640.366523-1-marcandre.lureau@redhat.com/
lands), since that was the reason I didn't include osdep.h iirc.

Anyway, if the rest of the series is accepted, the include should go
away too (should have done that on top).
diff mbox series

Patch

diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h
index c1d211a351..c409257c11 100644
--- a/include/qemu/atomic.h
+++ b/include/qemu/atomic.h
@@ -248,7 +248,7 @@ 
  * 4.3 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36793).
  */
 #if defined(__i386__) || defined(__x86_64__)
-#if !QEMU_GNUC_PREREQ(4, 4)
+#if !G_GNUC_CHECK_VERSION(4, 4)
 #if defined __x86_64__
 #define smp_mb()    ({ asm volatile("mfence" ::: "memory"); (void)0; })
 #else
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index c76281f354..cf044bab4a 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -7,21 +7,12 @@ 
 #ifndef COMPILER_H
 #define COMPILER_H
 
+#include "glib-compat.h"
+
 #if defined __clang_analyzer__ || defined __COVERITY__
 #define QEMU_STATIC_ANALYSIS 1
 #endif
 
-/*----------------------------------------------------------------------------
-| The macro QEMU_GNUC_PREREQ tests for minimum version of the GNU C compiler.
-| The code is a copy of SOFTFLOAT_GNUC_PREREQ, see softfloat-macros.h.
-*----------------------------------------------------------------------------*/
-#if defined(__GNUC__) && defined(__GNUC_MINOR__)
-# define QEMU_GNUC_PREREQ(maj, min) \
-         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
-#else
-# define QEMU_GNUC_PREREQ(maj, min) 0
-#endif
-
 #define QEMU_NORETURN __attribute__ ((__noreturn__))
 
 #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
@@ -104,7 +95,7 @@ 
                                    sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)))
 
 #if defined __GNUC__
-# if !QEMU_GNUC_PREREQ(4, 4)
+# if !G_GNUC_CHECK_VERSION(4, 4)
    /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
 #  define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
 # else
diff --git a/scripts/cocci-macro-file.h b/scripts/cocci-macro-file.h
index c6bbc05ba3..20eea6b708 100644
--- a/scripts/cocci-macro-file.h
+++ b/scripts/cocci-macro-file.h
@@ -19,7 +19,6 @@ 
  */
 
 /* From qemu/compiler.h */
-#define QEMU_GNUC_PREREQ(maj, min) 1
 #define QEMU_NORETURN __attribute__ ((__noreturn__))
 #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
 #define QEMU_SENTINEL __attribute__((sentinel))
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 58aea605d8..21a46d2e85 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -724,7 +724,7 @@  int cpu_exec(CPUState *cpu)
 
     /* prepare setjmp context for exception handling */
     if (sigsetjmp(cpu->jmp_env, 0) != 0) {
-#if defined(__clang__) || !QEMU_GNUC_PREREQ(4, 6)
+#if defined(__clang__) || !G_GNUC_CHECK_VERSION(4, 6)
         /* Some compilers wrongly smash all local variables after
          * siglongjmp. There were bug reports for gcc 4.5.0 and clang.
          * Reload essential local variables here for those compilers.