qemu/compiler: Remove unused special case code for GCC < 4.8
cover qemu/compiler: Remove unused special case code for GCC < 4.8
Since commit efc6c070aca we require GCC 4.8 minimum. Drop the special cases for older versions.
Philippe Mathieu-Daudé (3):
qemu/compiler: Simplify as all compilers support attribute
'gnu_printf'
qemu/atomic: Drop special case for unsupported compiler accel/tcg: Remove special case for GCC < 4.6
include/qemu/atomic.h | 17 ----------------- include/qemu/compiler.h | 19 ++++++++----------- accel/tcg/cpu-exec.c | 2 +- 3 files changed, 9 insertions(+), 29 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/3 qemu/compiler: Simplify as all compilers support attribute 'gnu_printf'
Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports the gnu_printf attribute.
We can safely remove the code introduced in commit 9c9e7d51bf0 ("Move macros GCC_ATTR and GCC_FMT_ATTR to common header file").
--- include/qemu/compiler.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
include/qemu/compiler.h +8 -11
@@ -104,17 +104,14 @@ sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)))#if defined __GNUC__ -# if !QEMU_GNUC_PREREQ (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 -/* Use gnu_printf when supported (qemu uses standard format strings). */ -# define GCC_FMT_ATTR (n, m) __attribute__((format(gnu_printf, n, m))) -# if defined(_WIN32) -/* Map __printf__ to __gnu_printf__ because we want standard format strings -* even when MinGW or GLib include files use __printf__. */ -# define __printf__ __gnu_printf__ -# endif +/* Use gnu_printf when supported (qemu uses standard format strings). */ +# define GCC_FMT_ATTR (n, m) __attribute__((format(gnu_printf, n, m))) +# if defined(_WIN32) +/* +* Map __printf__ to __gnu_printf__ because we want standard format strings +* even when MinGW or GLib include files use __printf__. +*/ +# define __printf__ __gnu_printf__# endif #else #define GCC_FMT_ATTR (n, m)
Signature · 1 line
2.26.2
Re: [PATCH 1/3] qemu/compiler: Simplify as all compilers support attribute 'gnu_printf'
Quoted 7 lines · Philippe Mathieu-Daudé
Since commit
efc6c070aca("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports thegnu_printfattribute.We can safely remove the code introduced in commit
9c9e7d51bf0("Move macrosGCC_ATTRandGCC_FMT_ATTRto common header file").
clang doesn't support the gnu_printf attribute, though:
$ clang --version clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin $ cat /tmp/zz9.c #include <stdio.h>
int monitor_printf(void *mon, const char *fmt, ...) __attribute__((format(gnu_printf, 2, 3)));
int main(void) {
printf("hello\n");
return 0;
}
$ clang -Wall -o /tmp/zz9 /tmp/zz9.c
/tmp/zz9.c:3:68: warning: 'format' attribute argument not supported:
gnu_printf [-Wignored-attributes]
int monitor_printf(void *mon, const char *fmt, ...)
__attribute__((format(gnu_printf, 2, 3)));
^
1 warning generated.thanks
-- PMM
Re: [PATCH 1/3] qemu/compiler: Simplify as all compilers support attribute 'gnu_printf'
In reply to Philippe Mathieu-DaudéQuoted 32 lines · Philippe Mathieu-Daudé
Since commit
efc6c070aca("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports thegnu_printfattribute.We can safely remove the code introduced in commit
9c9e7d51bf0("Move macrosGCC_ATTRandGCC_FMT_ATTRto common header file").Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/compiler.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)include/qemu/compiler.h +1
-11@@ -104,17 +104,14 @@ sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)))#if defined __GNUC__ -# if !QEMU_GNUC_PREREQ (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 -/* Use gnu_printf when supported (qemu uses standard format strings). */ -# define GCC_FMT_ATTR (n, m) __attribute__((format(gnu_printf, n, m))) -# if defined(_WIN32) -/* Map __printf__ to __gnu_printf__ because we want standard format strings -* even when MinGW or GLib include files use __printf__. */ -# define __printf__ __gnu_printf__ -# endif +/* Use gnu_printf when supported (qemu uses standard format strings). */
include/qemu/compiler.h line 117
Quoted 10 lines
include/qemu/compiler.h +7
-0+# define GCC_FMT_ATTR (n, m) __attribute__((format(gnu_printf, n, m))) +# if defined(_WIN32) +/* +* Map __printf__ to __gnu_printf__ because we want standard format strings +* even when MinGW or GLib include files use __printf__. +*/ +# define __printf__ __gnu_printf__# endif #else #define GCC_FMT_ATTR (n, m)
I think this can be simplified even more by using GLib's macros
#define GCC_FMT_ATTR(n, m) G_GNUC_PRINTF(n, m)
and ideally we'd then convert all crrent usage to the latter and drop GCC_FMT_ATTR.
https://developer.gnome.org/glib/2.64/glib-Miscellaneous-Macros.html
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 1/3] qemu/compiler: Simplify as all compilers support attribute 'gnu_printf'
Quoted 3 lines · Daniel P. Berrangé
I think this can be simplified even more by using GLib's macros
#define GCC_FMT_ATTR(n, m) G_GNUC_PRINTF(n, m)
At least on my system G_GNUC_PRINTF() expands to __format__(__printf__,...), not gnu_printf, so it is not quite what we want. (The difference is that on Windows hosts we still want to mark up our our logging functions as taking the glibc style format handling, not whatever the MS C library format escapes happen to be.)
At a minimum you'd need to keep in the "on Windows, redefine __printf__ to __gnu_printf__" logic.
See also commit 95df51a4a02a853.
thanks
-- PMM
Re: [PATCH 1/3] qemu/compiler: Simplify as all compilers support attribute 'gnu_printf'
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Daniel P. Berrangé
I think this can be simplified even more by using GLib's macros
#define GCC_FMT_ATTR(n, m) G_GNUC_PRINTF(n, m)At least on my system
G_GNUC_PRINTF()expands to__format__(__printf__,...), notgnu_printf, so it is not quite what we want. (The difference is that on Windows hosts we still want to mark up our our logging functions as taking the glibc style format handling, not whatever the MS C library format escapes happen to be.)
At a minimum you'd need to keep in the "on Windows, redefine__printf__to__gnu_printf__" logic.
Quoted 1 line
See also commit
95df51a4a02a853.
Oh, that's a bug in old GLib versions. I thought we had a new enough min to avoid that problem, but i guess not after all.
Modern GLib always uses gnu_printf even on Windows, as they're using a replacement GNU compatible printf impl for all the GLib APIs that take format strings.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 1/3] qemu/compiler: Simplify as all compilers support attribute 'gnu_printf'
Quoted 16 lines · Daniel P. Berrangé
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Daniel P. Berrangé
I think this can be simplified even more by using GLib's macros
#define GCC_FMT_ATTR(n, m) G_GNUC_PRINTF(n, m)At least on my system
G_GNUC_PRINTF()expands to__format__(__printf__,...), notgnu_printf, so it is not quite what we want. (The difference is that on Windows hosts we still want to mark up our our logging functions as taking the glibc style format handling, not whatever the MS C library format escapes happen to be.)
At a minimum you'd need to keep in the "on Windows, redefine__printf__to__gnu_printf__" logic.
Quoted 4 lines
Quoted 1 line
See also commit
95df51a4a02a853.Oh, that's a bug in old GLib versions. I thought we had a new enough min to avoid that problem, but i guess not after all.
Looks like the implementation changed 2 years ago:
https://gitlab.gnome.org/GNOME/glib/-/commit/98a0ab929d8c59ee27e5f470f11d077bb6a56749
not sure which glib version that would correspond to.
thanks
-- PMM
Re: [PATCH 1/3] qemu/compiler: Simplify as all compilers support attribute 'gnu_printf'
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Daniel P. Berrangé
Quoted 14 lines · Peter Maydell
Quoted 3 lines · Daniel P. Berrangé
I think this can be simplified even more by using GLib's macros
#define GCC_FMT_ATTR(n, m) G_GNUC_PRINTF(n, m)At least on my system
G_GNUC_PRINTF()expands to__format__(__printf__,...), notgnu_printf, so it is not quite what we want. (The difference is that on Windows hosts we still want to mark up our our logging functions as taking the glibc style format handling, not whatever the MS C library format escapes happen to be.)
At a minimum you'd need to keep in the "on Windows, redefine__printf__to__gnu_printf__" logic.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
See also commit
95df51a4a02a853.Oh, that's a bug in old GLib versions. I thought we had a new enough min to avoid that problem, but i guess not after all.
Looks like the implementation changed 2 years ago:
https://gitlab.gnome.org/GNOME/glib/-/commit/98a0ab929d8c59ee27e5f470f11d077bb6a56749
not sure which glib version that would correspond to.
Looks like 2.58.0, which is still a fair bit newer than our 2.48 min.
NB, only the macro changed - they were using GNU printf impl for many many years before that but simply had the wrong macro definition
We can just sacrifice -Wformat checking for Windows builds when using old GLib. People building natively on Windows with MSys probably have brand new GLib, and those using Fedora mingw / Debian MXE also have pretty new GLib.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 1/3] qemu/compiler: Simplify as all compilers support attribute 'gnu_printf'
Quoted 9 lines · Daniel P. Berrangé
Looks like 2.58.0, which is still a fair bit newer than our 2.48 min.
NB, only the macro changed - they were using GNU printf impl for many many years before that but simply had the wrong macro definition
We can just sacrifice -Wformat checking for Windows builds when using old GLib. People building natively on Windows with MSys probably have brand new GLib, and those using Fedora mingw / Debian MXE also have pretty new GLib.
In the past we also had different minimal GLib versions for Windows and POSIX systems.
Paolo
PATCH 2/3 qemu/atomic: Drop special case for unsupported compiler
In reply to Philippe Mathieu-DaudéSince commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which has the GCC BZ#36793 bug fixed.
We can safely remove the special case introduced in commit a281ebc11a6 ("virtio: add missing mb() on notification").
--- include/qemu/atomic.h | 17 ----------------- 1 file changed, 17 deletions(-)
include/qemu/atomic.h +0 -17
@@ -241,23 +241,6 @@#else /* __ATOMIC_RELAXED */ -/* -* We use GCC builtin if it's available, as that can use mfence on -* 32-bit as well, e.g. if built with -march=pentium-m. However, on -* i386 the spec is buggy, and the implementation followed it until -* 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 defined __x86_64__ -#define smp_mb () ({ asm volatile("mfence" ::: "memory"); (void)0; }) -#else -#define smp_mb () ({ asm volatile("lock; addl $0,0(%%esp) " ::: "memory"); (void)0; }) -#endif -#endif -#endif - -#ifdef __alpha__#define smp_read_barrier_depends () asm volatile("mb":::"memory")#endif
Signature · 1 line
2.26.2
Re: [PATCH 2/3] qemu/atomic: Drop special case for unsupported compiler
Quoted 13 lines · Philippe Mathieu-Daudé
Since commit
efc6c070aca("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which has the GCC BZ#36793 bug fixed.We can safely remove the special case introduced in commit
a281ebc11a6("virtio: add missingmb()on notification").include/qemu/atomic.h +0
-5-/* -* We use GCC builtin if it's available, as that can use mfence on -* 32-bit as well, e.g. if built with -march=pentium-m. However, on -* i386 the spec is buggy, and the implementation followed it until -* 4.3 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36793).
include/qemu/atomic.h line 258
Quoted 10 lines
include/qemu/atomic.h +0
-10-*/ -#if defined(__i386__) || defined(__x86_64__) -#if !QEMU_GNUC_PREREQ (4 ,4 ) -#if defined __x86_64__ -#define smp_mb () ({ asm volatile("mfence" ::: "memory"); (void)0; }) -#else -#define smp_mb () ({ asm volatile("lock; addl $0,0(%%esp) " ::: "memory"); (void)0; }) -#endif -#endif -#endif
You need to be a bit cautious about removing QEMU_GNUC_PREREQ() checks, because clang advertises itself as GCC 4.2 via the __GNUC__ and __GNUC_MINOR__ macros that QEMU_GNUC_PREREQ() tests, and so unless the code has explicitly handled clang via a different ifdef or feature test clang will be using the fallback codepath in cases like this. So you also need to find out whether all our supported versions of clang are OK with the gcc-4.4-and-up version of this code... (I think that deleting this set of #ifs means we end up with the "just use __sync_synchronize()" version of smp_mb() later on in the header?)
thanks
-- PMM
Marc-André Lureau
Reviewed-byRe: [PATCH 2/3] qemu/atomic: Drop special case for unsupported compiler
Hi
Quoted 23 lines · Peter Maydell
Quoted 10 lines · Philippe Mathieu-Daudé
Since commit
efc6c070aca("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which has the GCC BZ#36793 bug fixed.We can safely remove the special case introduced in commit
a281ebc11a6("virtio: add missingmb()on notification").include/qemu/atomic.h +0
-2-/* -* We use GCC builtin if it's available, as that can use mfence on include/qemu/atomic.h
Quoted 10 lines
include/qemu/atomic.h +0
-10-* 32-bit as well, e.g. if built with -march=pentium-m. However, on -* i386 the spec is buggy, and the implementation followed it until -* 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 defined __x86_64__ -#define smp_mb () ({ asm volatile("mfence" ::: "memory"); (void)0; }) -#else -#define smp_mb () ({ asm volatile("lock; addl $0,0(%%esp) " :::"memory"); (void)0; })
Quoted 16 lines
include/qemu/atomic.h line 258
Quoted 3 lines
include/qemu/atomic.h +0
-3-#endif -#endif -#endif You need to be a bit cautious about removing
QEMU_GNUC_PREREQ()checks, because clang advertises itself as GCC 4.2 via the__GNUC__and__GNUC_MINOR__macros thatQEMU_GNUC_PREREQ()tests, and so unless the code has explicitly handled clang via a different ifdef or feature test clang will be using the fallback codepath in cases like this. So you also need to find out whether all our supported versions of clang are OK with the gcc-4.4-and-up version of this code... (I think that deleting this set of #ifs means we end up with the "just use__sync_synchronize()" version ofsmp_mb()later on in the header?)
With clang 3.8 (xenial amd64) __ATOMIC_RELAXED is defined, so the chunk to remove which is x86-specific anyway, isn't reached.
Signature · 1 line
Marc-André Lureau
PATCH 3/3 accel/tcg: Remove special case for GCC < 4.6
In reply to Philippe Mathieu-DaudéSince commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8.
We can safely remove the special case for GCC 4.6 introduced in commit 0448f5f8b81 ("cpu-exec: Fix compiler warning (-Werror=clobbered)").
No change for Clang as we don't know.
--- accel/tcg/cpu-exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/cpu-exec.c +1 -1
@@ -703,7 +703,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__)/* 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.
Signature · 1 line
2.26.2
Re: [PATCH 3/3] accel/tcg: Remove special case for GCC < 4.6
Quoted 9 lines · Philippe Mathieu-Daudé
Since commit
efc6c070aca("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8.We can safely remove the special case for GCC 4.6 introduced in commit
0448f5f8b81("cpu-exec: Fix compiler warning (-Werror=clobbered)").
No change for Clang as we don't know.
Looking through the git history the inclusion of "clang" in this workaround is because a bug was noticed with the FreeBSD clang which prompted commit 6c78f29a2424622bfc9c3 in 2013. It's quite tempting to assume newer clangs have fixed this, but still I guess it's safest to leave the workaround in place...
thanks
-- PMM