Re: [Qemu-devel] Fiber switching and stack protection
Paolo, wasn't there a compiler option that works around the problem? I asked to test it (-D_MT) but never got any answer. I'd be surprised if defining _MT helped against compiler bugs. Well, -mthreads fixed it, and it should be the same as -D_MT -lmingwthrd. But we shouldn't need libmingwthrd, or do we? I've tried to add -mthreads to compiler options but nothing has changed, qemu still fails. This is likely a different bug than the original thread related bug. I'm using the mingw gcc 4.6.2, and I see the same thing as shown here: http://virtuallyfun.superglobalmegacorp.com/?p=1846 Something goes wrong during optimization with gcc 4.6.2, but it doesn't appear to be TLS related. Digging into it a bit, qemu_coroutine_switch() seems to break if it gets inlined. Can anyone else confirm if this one-line patch works for them? diff --git a/coroutine-win32.c b/coroutine-win32.c index 4179609..504873b 100644 --- a/coroutine-win32.c +++ b/coroutine-win32.c @@ -36,6 +36,7 @@ typedef struct static __thread CoroutineWin32 leader; static __thread Coroutine *current; +__attribute__ ((noinline)) CoroutineAction qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, CoroutineAction action) { I applied your patch to qemu 1.0 and it stopped crashing. By the way, I also created implementation of coroutine-win32.c, which uses WinAPI TLS functions directly (without using __thread specifiers). It works fine too. Pavel Dovgaluk
Re: [Qemu-devel] Fiber switching and stack protection
2012/4/16 Pavel Dovgaluk pavel.dovga...@ispras.ru: [snipped] By the way, I also created implementation of coroutine-win32.c, which uses WinAPI TLS functions directly (without using __thread specifiers). It works fine too. Patch is welcome. :D Pavel Dovgaluk
Re: [Qemu-devel] Fiber switching and stack protection
Il 16/04/2012 08:24, Pavel Dovgaluk ha scritto: By the way, I also created implementation of coroutine-win32.c, which uses WinAPI TLS functions directly (without using __thread specifiers). It works fine too. Cool, can you submit it? Paolo
Re: [Qemu-devel] Fiber switching and stack protection
Il 16/04/2012 08:24, Pavel Dovgaluk ha scritto: By the way, I also created implementation of coroutine-win32.c, which uses WinAPI TLS functions directly (without using __thread specifiers). It works fine too. Cool, can you submit it? I submitted the patch in a separate message. Pavel Dovgaluk
Re: [Qemu-devel] Fiber switching and stack protection
-Original Message- From: Paolo Bonzini [mailto:pbonz...@redhat.com] Sent: Thursday, April 12, 2012 8:57 PM To: Stefan Weil Cc: Kevin Wolf; 'qemu-devel'; Pavel Dovgaluk Subject: Re: [Qemu-devel] Fiber switching and stack protection Il 12/04/2012 18:31, Stefan Weil ha scritto: Am 12.04.2012 12:18, schrieb Paolo Bonzini: Il 12/04/2012 12:13, Kevin Wolf ha scritto: I guess it's this non-thread-local TLS once again, basically a compiler bug. You are right, this is a compiler bug with non-thread-local TLS. Paolo, wasn't there a compiler option that works around the problem? I asked to test it (-D_MT) but never got any answer. I'd be surprised if defining _MT helped against compiler bugs. Well, -mthreads fixed it, and it should be the same as -D_MT -lmingwthrd. But we shouldn't need libmingwthrd, or do we? I've tried to add -mthreads to compiler options but nothing has changed, qemu still fails. Pavel Dovgaluk
Re: [Qemu-devel] Fiber switching and stack protection
On 4/13/2012 6:25 AM, Pavel Dovgaluk wrote: -Original Message- From: Paolo Bonzini [mailto:pbonz...@redhat.com] Sent: Thursday, April 12, 2012 8:57 PM To: Stefan Weil Cc: Kevin Wolf; 'qemu-devel'; Pavel Dovgaluk Subject: Re: [Qemu-devel] Fiber switching and stack protection Il 12/04/2012 18:31, Stefan Weil ha scritto: Am 12.04.2012 12:18, schrieb Paolo Bonzini: Il 12/04/2012 12:13, Kevin Wolf ha scritto: I guess it's this non-thread-local TLS once again, basically a compiler bug. You are right, this is a compiler bug with non-thread-local TLS. Paolo, wasn't there a compiler option that works around the problem? I asked to test it (-D_MT) but never got any answer. I'd be surprised if defining _MT helped against compiler bugs. Well, -mthreads fixed it, and it should be the same as -D_MT -lmingwthrd. But we shouldn't need libmingwthrd, or do we? I've tried to add -mthreads to compiler options but nothing has changed, qemu still fails. This is likely a different bug than the original thread related bug. I'm using the mingw gcc 4.6.2, and I see the same thing as shown here: http://virtuallyfun.superglobalmegacorp.com/?p=1846 Something goes wrong during optimization with gcc 4.6.2, but it doesn't appear to be TLS related. Digging into it a bit, qemu_coroutine_switch() seems to break if it gets inlined. Can anyone else confirm if this one-line patch works for them? diff --git a/coroutine-win32.c b/coroutine-win32.c index 4179609..504873b 100644 --- a/coroutine-win32.c +++ b/coroutine-win32.c @@ -36,6 +36,7 @@ typedef struct static __thread CoroutineWin32 leader; static __thread Coroutine *current; +__attribute__ ((noinline)) CoroutineAction qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, CoroutineAction action) { Bob
Re: [Qemu-devel] Fiber switching and stack protection
Am 06.04.2012 12:38, schrieb Pavel Dovgaluk: Hello. Recently I tried to build qemu-1.0 with MinGW and start it with qcow file created with previous version of qemu. But after starting guest Windows loading process qemu had closed because of an exception. I figured out that this exception is “stack smashing” and it happened in qemu_coroutine_switch of coroutine-win32.c file. But when I remove -fstack-protector-all option from makefile nothing changes – an exception occurs again. Does anyone have an idea about such behavior? I guess it's this non-thread-local TLS once again, basically a compiler bug. Paolo, wasn't there a compiler option that works around the problem? Kevin
Re: [Qemu-devel] Fiber switching and stack protection
Il 12/04/2012 12:13, Kevin Wolf ha scritto: I guess it's this non-thread-local TLS once again, basically a compiler bug. Paolo, wasn't there a compiler option that works around the problem? Kevin I asked to test it (-D_MT) but never got any answer. Paolo
Re: [Qemu-devel] Fiber switching and stack protection
Am 12.04.2012 12:18, schrieb Paolo Bonzini: Il 12/04/2012 12:13, Kevin Wolf ha scritto: I guess it's this non-thread-local TLS once again, basically a compiler bug. Paolo, wasn't there a compiler option that works around the problem? Kevin I asked to test it (-D_MT) but never got any answer. Paolo I'd be surprised if defining _MT helped against compiler bugs. It will change the declaration of some functions in stdio.h, but the buggy compiler will still not create TLS. Cheers, Stefan
Re: [Qemu-devel] Fiber switching and stack protection
Il 12/04/2012 18:31, Stefan Weil ha scritto: Am 12.04.2012 12:18, schrieb Paolo Bonzini: Il 12/04/2012 12:13, Kevin Wolf ha scritto: I guess it's this non-thread-local TLS once again, basically a compiler bug. Paolo, wasn't there a compiler option that works around the problem? I asked to test it (-D_MT) but never got any answer. I'd be surprised if defining _MT helped against compiler bugs. Well, -mthreads fixed it, and it should be the same as -D_MT -lmingwthrd. But we shouldn't need libmingwthrd, or do we? Paolo It will change the declaration of some functions in stdio.h, but the buggy compiler will still not create TLS.