Patchwork gcc auto-omit-frame-pointer vs msvc longjmp

login
register
mail settings
Submitter Kai Tietz
Date Oct. 20, 2011, 3:34 p.m.
Message ID <CAEwic4Zey2f6fzSOAiGtyxuBnN2zSPwQCcDdTDdL8-DOiqC2GQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/120830/
State New
Headers show

Comments

Kai Tietz - Oct. 20, 2011, 3:34 p.m.
Hi,

For trunk-version I have a tentative patch for this issue.  On 4.6.x
and older branches this doesn't work, as here we can't differenciate
that easy between ms- and sysv-abi.

But could somebody give this patch a try?

Regards,
Kai

ChangeLog

        * config/i386/i386.c (ix86_frame_pointer_required): Enforce use of
        frame-pointer for 32-bit ms-abi, if setjmp is used.
xunxun - Oct. 22, 2011, 5:13 a.m.
Hi, all

     It seems that gcc's auto-omit-frame-pointer has other problems.

     The example is from mingw bug tracker: 
http://sourceforge.net/tracker/?func=detail&aid=3426555&group_id=2435&atid=102435

     g++ -O3 main.cpp       running will crash.
     g++ -O2 main.cpp       running no crash.
     g++ -O3 -fno-omit-frame-pointer    running no crash.

     I don't know in the end which optimize option defaultly contains 
this switch "-fomit-frame-pointer" on i686-pc-mingw32 or x86_64-w64-mingw32?
xunxun - Oct. 22, 2011, 5:21 a.m.
于 2011/10/22 13:13, xunxun 写道:
> Hi, all
>
>     It seems that gcc's auto-omit-frame-pointer has other problems.
>
>     The example is from mingw bug tracker: 
> http://sourceforge.net/tracker/?func=detail&aid=3426555&group_id=2435&atid=102435
>
>     g++ -O3 main.cpp       running will crash.
>     g++ -O2 main.cpp       running no crash.
>     g++ -O3 -fno-omit-frame-pointer    running no crash.
>
>     I don't know in the end which optimize option defaultly contains 
> this switch "-fomit-frame-pointer" on i686-pc-mingw32 or 
> x86_64-w64-mingw32?
>
It crashes on Win7.
Kai Tietz - Oct. 22, 2011, 11:19 a.m.
2011/10/22 xunxun <xunxun1982@gmail.com>:
> 于 2011/10/22 13:13, xunxun 写道:
>>
>> Hi, all
>>
>>    It seems that gcc's auto-omit-frame-pointer has other problems.
>>
>>    The example is from mingw bug tracker:
>> http://sourceforge.net/tracker/?func=detail&aid=3426555&group_id=2435&atid=102435
>>
>>    g++ -O3 main.cpp       running will crash.
>>    g++ -O2 main.cpp       running no crash.
>>    g++ -O3 -fno-omit-frame-pointer    running no crash.
>>
>>    I don't know in the end which optimize option defaultly contains this
>> switch "-fomit-frame-pointer" on i686-pc-mingw32 or x86_64-w64-mingw32?
>>
> It crashes on Win7.

Well, this issue isn't related to this thread.  It is more related to
dw2 and SjLj used.  For toolchains using dw2 exception mechanism, you
will see this crash.  By using SjLj you won't (thanks for checking
this).
This shows indeed my strong concerns about dw2 exception mechanism for
32-bit Windows targets.  The implementation depends too much on
code-patterns and is therefore a bit inconsitant.  Secondly it causes
harm if you try to throw exceptions over VC generated code.  So I
would strongly recomment to use the slower, but more reliable SjLj
throwing mechanism on Windows 32-bit.

Regards,
Kai
asmwarrior - Oct. 22, 2011, 2:23 p.m.
On 2011-10-20 23:34, Kai Tietz wrote:
> Hi,
> 
> For trunk-version I have a tentative patch for this issue.  On 4.6.x
> and older branches this doesn't work, as here we can't differenciate
> that easy between ms- and sysv-abi.
> 
> But could somebody give this patch a try?
> 
> Regards,
> Kai
> 
> ChangeLog
> 
>          * config/i386/i386.c (ix86_frame_pointer_required): Enforce use of
>          frame-pointer for 32-bit ms-abi, if setjmp is used.
> 
> Index: i386.c
> ===================================================================
> --- i386.c      (revision 180099)
> +++ i386.c      (working copy)
> @@ -8391,6 +8391,10 @@
>     if (SUBTARGET_FRAME_POINTER_REQUIRED)
>       return true;
> 
> +  /* For older 32-bit runtimes setjmp requires valid frame-pointer.  */
> +  if (TARGET_32BIT_MS_ABI&&  cfun->calls_setjmp)
> +    return true;
> +
>     /* In ix86_option_override_internal, TARGET_OMIT_LEAF_FRAME_POINTER
>        turns off the frame pointer by default.  Turn it back on now if
>        we've not got a leaf function.  */
> 

I just see two related links about this issue:

see:
http://stackoverflow.com/questions/5887552/setjmp-and-omit-frame-pointer

and

http://connect.microsoft.com/VisualStudio/feedback/details/666704/visual-c-generates-incorrect-code-with-omit-frame-pointer-and-setjmp

I'm not sure microsoft has fix this issue.

asmwarrior
ollydbg from codeblocks' forum
Bob Breuer - Oct. 24, 2011, 2:45 p.m.
Kai Tietz wrote:
> Hi,
> 
> For trunk-version I have a tentative patch for this issue.  On 4.6.x
> and older branches this doesn't work, as here we can't differenciate
> that easy between ms- and sysv-abi.
> 
> But could somebody give this patch a try?
> 
> Regards,
> Kai
> 
> ChangeLog
> 
>         * config/i386/i386.c (ix86_frame_pointer_required): Enforce use of
>         frame-pointer for 32-bit ms-abi, if setjmp is used.
> 
> Index: i386.c
> ===================================================================
> --- i386.c      (revision 180099)
> +++ i386.c      (working copy)
> @@ -8391,6 +8391,10 @@
>    if (SUBTARGET_FRAME_POINTER_REQUIRED)
>      return true;
> 
> +  /* For older 32-bit runtimes setjmp requires valid frame-pointer.  */
> +  if (TARGET_32BIT_MS_ABI && cfun->calls_setjmp)
> +    return true;
> +
>    /* In ix86_option_override_internal, TARGET_OMIT_LEAF_FRAME_POINTER
>       turns off the frame pointer by default.  Turn it back on now if
>       we've not got a leaf function.  */
> 

For a gcc 4.7 snapshot, this does fix the longjmp problem that I
encountered.  So aside from specifying -fno-omit-frame-pointer for
affected files, what can be done for 4.6?

Bob

Patch

Index: i386.c
===================================================================
--- i386.c      (revision 180099)
+++ i386.c      (working copy)
@@ -8391,6 +8391,10 @@ 
   if (SUBTARGET_FRAME_POINTER_REQUIRED)
     return true;

+  /* For older 32-bit runtimes setjmp requires valid frame-pointer.  */
+  if (TARGET_32BIT_MS_ABI && cfun->calls_setjmp)
+    return true;
+
   /* In ix86_option_override_internal, TARGET_OMIT_LEAF_FRAME_POINTER
      turns off the frame pointer by default.  Turn it back on now if
      we've not got a leaf function.  */