From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Stefan Weil <sw@weilnetz.de>
Subject: [Qemu-devel] [PULL 10/14] cpu-exec: Fix compiler warning (-Werror=clobbered)
Date: Wed, 4 Nov 2015 17:18:28 +0100 [thread overview]
Message-ID: <1446653912-116150-11-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1446653912-116150-1-git-send-email-pbonzini@redhat.com>
From: Stefan Weil <sw@weilnetz.de>
Reloading of local variables after sigsetjmp is only needed for some
buggy compilers.
The code which should reload these variables causes compiler warnings
with gcc 4.7 when compiler optimizations are enabled:
cpu-exec.c:204:15: error:
variable ‘cpu’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered]
cpu-exec.c:207:15: error:
variable ‘cc’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered]
cpu-exec.c:202:28: error:
argument ‘env’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered]
Now this code is only used for compilers which need it
(and gcc 4.5.x, x > 0 which does not need it but won't give warnings).
There were bug reports for clang and gcc 4.5.0, while gcc 4.5.1
was reported to work fine without the reload code. For clang it
is not clear which versions are affected, so simply keep the status quo
for all clang compilations. This can be improved later.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
Message-Id: <1443266606-21400-1-git-send-email-sw@weilnetz.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
cpu-exec.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/cpu-exec.c b/cpu-exec.c
index 7eef083..2cfb3d0 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -539,15 +539,27 @@ int cpu_exec(CPUState *cpu)
only be set by a memory fault) */
} /* for(;;) */
} else {
- /* Reload env after longjmp - the compiler may have smashed all
- * local variables as longjmp is marked 'noreturn'. */
+#if defined(__clang__) || !QEMU_GNUC_PREREQ(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.
+ * Newer versions of gcc would complain about this code (-Wclobbered). */
cpu = current_cpu;
cc = CPU_GET_CLASS(cpu);
- cpu->can_do_io = 1;
#ifdef TARGET_I386
x86_cpu = X86_CPU(cpu);
env = &x86_cpu->env;
#endif
+#else /* buggy compiler */
+ /* Assert that the compiler does not smash local variables. */
+ g_assert(cpu == current_cpu);
+ g_assert(cc == CPU_GET_CLASS(cpu));
+#ifdef TARGET_I386
+ g_assert(x86_cpu == X86_CPU(cpu));
+ g_assert(env == &x86_cpu->env);
+#endif
+#endif /* buggy compiler */
+ cpu->can_do_io = 1;
tb_lock_reset();
}
} /* for(;;) */
--
1.8.3.1
next prev parent reply other threads:[~2015-11-04 16:18 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-04 16:18 [Qemu-devel] [PULL 00/14] Misc changes for QEMU 2.4-rc1 Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 01/14] file_ram_alloc: propagate error to caller instead of terminating QEMU Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 02/14] scripts/text2pod.pl: Escape left brace Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 03/14] target-i386: fix pcmpxstrx equal-ordered (strstr) mode Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 04/14] ioport: do not use CPU_LOG_IOPORT Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 05/14] qemu-log: remove -d ioport Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 06/14] pc: Set hw_version on all machine classes Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 07/14] osdep: Rename qemu_{get, set}_version() to qemu_{, set_}hw_version() Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 08/14] megasas: Use qemu_hw_version() instead of QEMU_VERSION Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 09/14] memory: call begin, log_start and commit when registering a new listener Paolo Bonzini
2015-11-04 16:18 ` Paolo Bonzini [this message]
2015-11-04 16:18 ` [Qemu-devel] [PULL 11/14] configure: disallow ccache during compile tests Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 12/14] backends/hostmem-file: Allow to specify full pathname for backing file Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 13/14] iscsi: Translate scsi sense into error code Paolo Bonzini
2015-11-04 16:18 ` [Qemu-devel] [PULL 14/14] configure: disable FORTIFY_SOURCE under clang Paolo Bonzini
2015-11-04 16:34 ` [Qemu-devel] [PULL 00/14] Misc changes for QEMU 2.4-rc1 Peter Maydell
2015-11-04 16:36 ` Paolo Bonzini
2015-11-05 4:58 ` Fam Zheng
2015-11-05 8:02 ` Peter Maydell
2015-11-04 16:53 ` Denis V. Lunev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1446653912-116150-11-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).