From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zr92O-0004fh-DX for qemu-devel@nongnu.org; Tue, 27 Oct 2015 14:32:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zr92J-0002Vr-Jp for qemu-devel@nongnu.org; Tue, 27 Oct 2015 14:32:00 -0400 Received: from [2a03:4000:1::4e2f:c7ac:d] (port=53677 helo=v220110690675601.yourvserver.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zr92J-0002VS-AS for qemu-devel@nongnu.org; Tue, 27 Oct 2015 14:31:55 -0400 Message-ID: <562FC317.3030402@weilnetz.de> Date: Tue, 27 Oct 2015 19:31:51 +0100 From: Stefan Weil MIME-Version: 1.0 References: <1443266606-21400-1-git-send-email-sw@weilnetz.de> In-Reply-To: <1443266606-21400-1-git-send-email-sw@weilnetz.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 for 2.5] cpu-exec: Fix compiler warning (-Werror=clobbered) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developer , =?UTF-8?B?QW5kcmVhcyBGw6RyYmVy?= Cc: Peter Maydell , Jan Kiszka , Dimitry Andric , =?UTF-8?B?SsO8cmdlbiBMb2Nr?= Am 26.09.2015 um 13:23 schrieb Stefan Weil: > Reloading of local variables after sigsetjmp is only needed for some > buggy compilers. >=20 > The code which should reload these variables causes compiler warnings > with gcc 4.7 when compiler optimizations are enabled: >=20 > cpu-exec.c:204:15: error: > variable =E2=80=98cpu=E2=80=99 might be clobbered by =E2=80=98longjmp=E2= =80=99 or =E2=80=98vfork=E2=80=99 [-Werror=3Dclobbered] > cpu-exec.c:207:15: error: > variable =E2=80=98cc=E2=80=99 might be clobbered by =E2=80=98longjmp=E2= =80=99 or =E2=80=98vfork=E2=80=99 [-Werror=3Dclobbered] > cpu-exec.c:202:28: error: > argument =E2=80=98env=E2=80=99 might be clobbered by =E2=80=98longjmp=E2= =80=99 or =E2=80=98vfork=E2=80=99 [-Werror=3Dclobbered] >=20 > 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). >=20 > 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. >=20 > Signed-off-by: Stefan Weil > --- >=20 > v2: Don't remove the code which causes the warnings, but use it > only with clang or gcc < 4.6. >=20 > v3: Add assertions for compilers which hopefully don't smash variables > (suggested by Peter Maydell). >=20 > I started v1 of this patch two years ago to prepare support for > builds with compiler option -Wextra. >=20 > See http://patchwork.ozlabs.org/patch/287593/ for the latest > discussion on this issue. >=20 >=20 > cpu-exec.c | 18 +++++++++++++++--- > 1 file changed, 15 insertions(+), 3 deletions(-) >=20 > diff --git a/cpu-exec.c b/cpu-exec.c > index 8fd56a6..7dab85a 100644 > --- a/cpu-exec.c > +++ b/cpu-exec.c > @@ -538,15 +538,27 @@ int cpu_exec(CPUState *cpu) > only be set by a memory fault) */ > } /* for(;;) */ > } else { > - /* Reload env after longjmp - the compiler may have smashe= d 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 cl= ang. > + * Reload essential local variables here for those compile= rs. > + * Newer versions of gcc would complain about this code (-= Wclobbered). */ > cpu =3D current_cpu; > cc =3D CPU_GET_CLASS(cpu); > - cpu->can_do_io =3D 1; > #ifdef TARGET_I386 > x86_cpu =3D X86_CPU(cpu); > env =3D &x86_cpu->env; > #endif > +#else /* buggy compiler */ > + /* Assert that the compiler does not smash local variables= . */ > + g_assert(cpu =3D=3D current_cpu); > + g_assert(cc =3D=3D CPU_GET_CLASS(cpu)); > +#ifdef TARGET_I386 > + g_assert(x86_cpu =3D=3D X86_CPU(cpu)); > + g_assert(env =3D=3D &x86_cpu->env); > +#endif > +#endif /* buggy compiler */ > + cpu->can_do_io =3D 1; > tb_lock_reset(); > } > } /* for(;;) */ >=20 Ping. Is there any chance to get this patch into version 2.5? I'd be happy to remove this 2 year old issue from my list of open patches. Regards, Stefan