Bug 56870 - @catch handler broken with SEH
Summary: @catch handler broken with SEH
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: objc (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-07 21:55 UTC by js-gcc
Modified: 2014-02-18 17:10 UTC (History)
1 user (show)

See Also:
Host:
Target: *-*-mingw-* *-*-cygwin*
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description js-gcc 2013-04-07 21:55:29 UTC
When trying to use ObjC exceptions with the new SEH support, the caught object is not the ObjC object, but the _Unwind_Exception instead. Example:

@try {
    id e = [Object new];
    printf("@throw %p\n", e);
    @throw e;
} @catch (id e) {
    printf("@catch %p\n", e);
    @throw e;
}

Expected behaviour: Both are the same pointer.
Observed behaviour: They differ.

Looking further into it, the second pointer is the pointer to the _Unwind_Exception (I added debug code in objc_exception_throw that outputs the pointer after the malloc. It is always the same that's received in the catch).

So it seems the generated landing pad for ObjC code is wrong when using SEH. I think it is correct that the landing pad receives the _Unwind_Exception and not the ObjC object. But the landing pad needs to get the ObjC exception out of the _Unwind_Exception and give that back to the user instead of the _Unwind_Exception, which the user should never see.

This seems to happen not only with 4.8, but also with 4.9.

I marked this bug as blocker, as 4.8 made SEH the default, effectively breaking ObjC execptions on Windows.
Comment 1 js-gcc 2013-04-07 22:49:06 UTC
Why was this lowered to normal? This is a regression, code that worked fine with GCC 4.7 now just crashes. It makes ObjC code that uses exceptions unusable, as it only crashes.
Comment 2 Steven Bosscher 2013-04-08 06:47:46 UTC
(In reply to comment #1)
> Why was this lowered to normal? This is a regression, code that worked fine
> with GCC 4.7 now just crashes. It makes ObjC code that uses exceptions
> unusable, as it only crashes.

Because ObjC is not a release blocking language, and windows is not a 
primary platform. That doesn't mean it won't be fixed, that depends on
whether someone is volunteering to fix this, just like for any other
bug report.
Comment 3 Kai Tietz 2013-04-08 06:51:58 UTC
Hmm, this bug looks like a duplicate of PR/56742
Could you test if provided patch in PR/56742 fixes your issue?
Comment 4 Kai Tietz 2014-02-18 17:03:26 UTC
Author: ktietz
Date: Tue Feb 18 17:02:54 2014
New Revision: 207849

URL: http://gcc.gnu.org/viewcvs?rev=207849&root=gcc&view=rev
Log:
2014-02-18  Kai Tietz  <ktietz@redhat.com>
	Jonathan Schleifer  <js@webkeks.org>

	PR objc/56870
	* unwind-seh.c (_GCC_specific_handler): Pass proper
	value to unwind-handler.


Modified:
    trunk/libgcc/ChangeLog
    trunk/libgcc/unwind-seh.c
Comment 5 Kai Tietz 2014-02-18 17:05:09 UTC
Author: ktietz
Date: Tue Feb 18 17:04:38 2014
New Revision: 207850

URL: http://gcc.gnu.org/viewcvs?rev=207850&root=gcc&view=rev
Log:
2014-02-18  Kai Tietz  <ktietz@redhat.com>
	Jonathan Schleifer  <js@webkeks.org>

	PR objc/56870
	* unwind-seh.c (_GCC_specific_handler): Pass proper
	value to unwind-handler.


Modified:
    branches/gcc-4_8-branch/libgcc/ChangeLog
    branches/gcc-4_8-branch/libgcc/unwind-seh.c
Comment 6 Kai Tietz 2014-02-18 17:10:02 UTC
Fixed