From patchwork Sat Jul 2 09:08:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 102986 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3CB72B6F5A for ; Sat, 2 Jul 2011 19:14:40 +1000 (EST) Received: from localhost ([::1]:43982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcwHc-0000NG-J9 for incoming@patchwork.ozlabs.org; Sat, 02 Jul 2011 05:14:36 -0400 Received: from eggs.gnu.org ([140.186.70.92]:55865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcwBs-0008Cq-3S for qemu-devel@nongnu.org; Sat, 02 Jul 2011 05:08:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QcwBq-0006R3-8R for qemu-devel@nongnu.org; Sat, 02 Jul 2011 05:08:39 -0400 Received: from mail-qw0-f45.google.com ([209.85.216.45]:48212) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcwBp-0006Qx-Ti for qemu-devel@nongnu.org; Sat, 02 Jul 2011 05:08:38 -0400 Received: by qwj8 with SMTP id 8so2349145qwj.4 for ; Sat, 02 Jul 2011 02:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=bNXSalC1wmVx86eHDyG0rpyKf5L6W5IMK4eK00i+o6Q=; b=ATJGkILVWpjui7746IoASMvTLA1W32UtLHxzP471akglR6TdWfiIEDb9ANco7shnJh BxwKT2J/6B5Rk05rLq6jKvOIA09M0U0d5BqCzcxMyfFZmHbySwIg+dgX+yzgN3aeyS21 zWCqGl74f8KPsxYqPNb+DiZID5gzcFgMk2/k0= Received: by 10.224.190.136 with SMTP id di8mr3127196qab.255.1309597717170; Sat, 02 Jul 2011 02:08:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.73.129 with HTTP; Sat, 2 Jul 2011 02:08:17 -0700 (PDT) In-Reply-To: <4E0ECDDB.9030001@web.de> References: <4E0CA885.2050308@siemens.com> <4E0ECDDB.9030001@web.de> From: Blue Swirl Date: Sat, 2 Jul 2011 12:08:17 +0300 Message-ID: To: Jan Kiszka X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.216.45 Cc: TeLeMan , qemu-devel Subject: Re: [Qemu-devel] [PATCH] tcg: Reload local variables after return from longjmp X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Sat, Jul 2, 2011 at 10:50 AM, Jan Kiszka wrote: > From: Jan Kiszka > > Recent compilers look deep into cpu_exec, find longjmp as a noreturn > function and decide to smash some stack variables as they won't be used > again. This may lead to env becoming invalid after return from setjmp, > causing crashes. Fix it by reloading env from cpu_single_env in that > case. Nice. Could you try if gcc flag -Wclobbered catches something using your compiler without your patch: commit f826f0d0f5cf5dd18a0d34159c1a3bc8f2e6ddf4 Author: Blue Swirl Date: Sun Sep 26 11:58:38 2010 +0000 Add gcc warning -Wclobbered Signed-off-by: Blue Swirl > Signed-off-by: Jan Kiszka > --- >  cpu-exec.c |    4 ++++ >  1 files changed, 4 insertions(+), 0 deletions(-) > > diff --git a/cpu-exec.c b/cpu-exec.c > index 20e3ec4..de0d716 100644 > --- a/cpu-exec.c > +++ b/cpu-exec.c > @@ -587,6 +587,10 @@ int cpu_exec(CPUState *env) >                 /* reset soft MMU for next block (it can currently >                    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'. */ > +            env = cpu_single_env; >         } >     } /* for(;;) */ > > diff --git a/configure b/configure index 88159ac..2417205 100755 --- a/configure +++ b/configure @@ -1038,7 +1038,7 @@ fi gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits" gcc_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $gcc_flags" gcc_flags="-Wmissing-include-dirs -Wempty-body -Wnested-externs $gcc_flags" -gcc_flags="-fstack-protector-all -Wendif-labels $gcc_flags" +gcc_flags="-fstack-protector-all -Wendif-labels -Wclobbered $gcc_flags" cat > $TMPC << EOF int main(void) { return 0; } EOF