public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bob Breuer <breuerr@mc.net>
To: Kai Tietz <ktietz70@googlemail.com>
Cc: "gcc@gcc.gnu.org" <gcc@gcc.gnu.org>,
	 Mark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>,
	qemu-devel <qemu-devel@nongnu.org>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] gcc auto-omit-frame-pointer vs msvc longjmp
Date: Tue, 18 Oct 2011 04:20:00 -0000	[thread overview]
Message-ID: <4E9CAACE.4070804@mc.net> (raw)
In-Reply-To: <CAEwic4Yw0nc9yij+SGMdXMy2R11FyXVWQ4TChczQsNGuVFqkAQ@mail.gmail.com>

Kai Tietz wrote:
> 2011/10/17 Bob Breuer <breuerr@mc.net>:
>> Richard Henderson wrote:
>>> On 10/17/2011 07:09 AM, Bob Breuer wrote:
>>>> I don't think this is a free/g_free issue.  If I use the following
>>>> patch, then I at least get the openbios messages:
>>>>
>>>> diff --git a/cpu-exec.c b/cpu-exec.c
>>>> index a9fa608..dfbd6ea 100644
>>>> --- a/cpu-exec.c
>>>> +++ b/cpu-exec.c
>>>> @@ -180,6 +180,7 @@ static void cpu_handle_debug_exception(CPUState
>>>>  /* main execution loop */
>>>>
>>>>  volatile sig_atomic_t exit_request;
>>>> +register void *ebp asm("ebp");
>>>>
>>>>  int cpu_exec(CPUState *env)
>>>>  {
>>>> @@ -233,6 +234,8 @@ int cpu_exec(CPUState *env)
>>>>
>>>>      /* prepare setjmp context for exception handling */
>>>>      for(;;) {
>>>> +        int dummy = 0;
>>>> +        ebp = &dummy;
>>> See if
>>>
>>>   asm("" : : : "ebp");
>>>
>>> also solves the problem.
>> No, that doesn't fix it.
>>
>>>> Google finds a mention of longjmp failing with -fomit-frame-pointer:
>>>> http://lua-users.org/lists/lua-l/2005-02/msg00158.html
>>>>
>>>> Looks like gcc 4.6 turns on -fomit-frame-pointer by default.
>>> Hmm.  This is the first I've heard of a longjmp implementation
>>> failing without a frame pointer.  Presumably this is with the
>>> mingw i.e. msvc libc?
>> Yeah, mingw from www.mingw.org which I believe uses msvcrt.dll, package
>> gcc-core-4.6.1-2-mingw32-bin.
>>
>>> This is something that could be worked around in gcc, I suppose.
>>> We recognize longjmp for some things, we could force the use of
>>> a frame pointer for msvc targets too.
>>>
>>> For now it might be best to simply force -fno-omit-frame-pointer
>>> for mingw host in the configure script.
>> Here's a testcase that crashes on the longjmp:
>>
>> #include <stdio.h>
>> #include <setjmp.h>
>>
>> jmp_buf env;
>>
>> int test(void)
>> {
>>  int i;
>>
>>  asm("xor %%ebp,%%ebp" ::: "ebp");
>>
>>  i = setjmp(env);
>>  printf("i = %d\n", i);
>>
>>  if (i == 0)
>>    longjmp(env, 2);
>>
>>  return i;
>> }
>>
>> int main(void)
>> {
>>  return test();
>> }
>>
>> Remove the asm statement to make it not crash.  Obviously with
>> omit-frame-pointer, gcc can shove anything into ebp.
>>
>> Bob
> 
> This crash isn'r related to ebp existing, or not. The issue is the
> hidden argument of setjmp, which is missing.  If you can try the
> following at top of file after include section.
> 
> #define setjmp(BUF) _setjmpex((BUF), NULL)
> int __cdecl __attribute__ ((__nothrow__,__returns_twice__))
> _setjmp3(jmp_buf _Buf, void *_Ctx);
> ...

Did you mean _setjmp3 instead of _setjmpex?  With _setjmp3, it works
without the asm, but still crashes if I zero out ebp before the setjmp.
 Aren't the function arguments on the stack anyway?

> 
> This will work as expected with or without omit-frame-pointer.
> 
> The issue is that setjmp has a second (undocumented as usual)
> argument, which has a meaning.

So why does my testcase above fail with the asm, but work without the
asm statement?  Compile it with gcc -O2 and try it yourself.

> 
> Regards,
> Kai
> 
> PS:  _setjmp3 is an export from msvcrt.dll.  So if symbol is missing
> on link, simply specify msvcrt.dll as argument to link-line.


  reply	other threads:[~2011-10-17 22:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4E9BB180.6080506@mc.net>
     [not found] ` <4E9C0497.2000605@siriusit.co.uk>
     [not found]   ` <4E9C3703.3040109@mc.net>
2011-10-17 21:20     ` Richard Henderson
2011-10-17 21:32       ` [Qemu-devel] " Blue Swirl
2011-10-17 22:23         ` Richard Henderson
2011-10-17 22:56       ` Bob Breuer
2011-10-18  2:06         ` Kai Tietz
2011-10-18  4:20           ` Bob Breuer [this message]
2011-10-18  4:22             ` Kai Tietz
2011-10-20  3:26               ` Bob Breuer
2011-10-20  4:18                 ` Richard Henderson
2011-10-20  6:08                 ` xunxun
2011-10-20 15:01                   ` Kai Tietz
2011-10-20 17:12                     ` Kai Tietz
2011-10-21 22:47                       ` jojelino
2011-10-22 12:30                         ` xunxun
2011-10-22 13:18                           ` xunxun
2011-10-22 14:21                             ` Kai Tietz
2011-10-22 22:59                       ` asmwarrior
2011-10-24 20:05                       ` [Qemu-devel] " Bob Breuer
2011-10-24 23:25                         ` Kai Tietz
2011-10-25 17:00                           ` Bob Breuer
2011-10-20 14:16                 ` jojelino

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=4E9CAACE.4070804@mc.net \
    --to=breuerr@mc.net \
    --cc=gcc@gcc.gnu.org \
    --cc=ktietz70@googlemail.com \
    --cc=mark.cave-ayland@siriusit.co.uk \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).