qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Re: gcc 4.4 miscompiling cpu_exec() ?


From: Paolo Bonzini
Subject: [Qemu-devel] Re: gcc 4.4 miscompiling cpu_exec() ?
Date: Tue, 23 Feb 2010 18:58:47 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.7) Gecko/20100120 Fedora/3.0.1-1.fc12 Lightning/1.0b2pre Thunderbird/3.0.1

On 02/23/2010 03:50 PM, Jay Foad wrote:
I'm building QEMU mipsel-linux-user with Ubuntu's GCC 4.4 on an x86
host. Whenever I try to run a trivial MIPS executable, QEMU segfaults
in cpu_loop() shortly after the call to cpu_mips_exec().

The problem seems to be that cpu_exec() doesn't preserve ebp. It tries to:

     saved_env_reg = (host_reg_t) env;

where env is a global variable decorated with asm("ebp"). This saves
ebp to the stack, but later on, in some function inlined into
cpu_exec(), the value on the stack gets overwritten with something
else.

Can you try this patch:

diff --git a/cpu-exec.c b/cpu-exec.c
index 51aa416..bfaf908 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -215,7 +215,7 @@ static void cpu_handle_debug_exception(CPUState *env)

 int cpu_exec(CPUState *env1)
 {
-    host_reg_t saved_env_reg;
+    volatile host_reg_t saved_env_reg;
     int ret, interrupt_request;
     TranslationBlock *tb;
     uint8_t *tc_ptr;
@@ -230,8 +230,8 @@ int cpu_exec(CPUState *env1)
        value, so that files not including target-xyz/exec.h are free to
        use it.  */
     QEMU_BUILD_BUG_ON (sizeof (saved_env_reg) != sizeof (env));
-    saved_env_reg = (host_reg_t) env;
     asm("");
+    saved_env_reg = (host_reg_t) env;
     env = env1;

 #if defined(TARGET_I386)

and if it works, possibly only each hunk of it?

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]