From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1670 invoked by alias); 15 Feb 2014 17:27:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 1652 invoked by uid 89); 15 Feb 2014 17:27:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.4 required=5.0 tests=BAYES_00,RCVD_IN_RP_RNBL,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC autolearn=no version=3.3.2 X-HELO: webkeks.org Received: from ip-62-143-88-147.unitymediagroup.de (HELO webkeks.org) (62.143.88.147) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Feb 2014 17:27:44 +0000 Received: from localhost.localdomain (unknown [IPv6:2001:470:73ae:0:21a:92ff:feb4:69a9]) (Authenticated sender: js) by webkeks.org (Postfix) with ESMTPSA id ECC8819A0B8 for ; Sat, 15 Feb 2014 18:27:38 +0100 (CET) Date: Sat, 15 Feb 2014 17:27:00 -0000 From: Jonathan Schleifer To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fixing SEH exceptions for languages != C++ Message-ID: <20140215182737.23f55712@webkeks.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/kTS6uvUb2+ZiLF.5APphCkV" X-SW-Source: 2014-02/txt/msg00967.txt.bz2 --MP_/kTS6uvUb2+ZiLF.5APphCkV Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1220 Hi! The following patch fixes a bug in SEH exception handling that made it crash with ObjC (and most likely other languages as well). The problem is that the SEH exception handler always passes the unwind exception as 4th parameter to RtlUnwindEx, which RtlUnwindEx then later passes to the landing pad as argument. This works for C++, as libstdc++ sets data register 0 to the unwind exception anyway, but it crashes for ObjC as the landing pad expects the thrown object to be in data register 0. The solution is of course to fix the SEH wrapper to get the value that was set for data register 0 using _Unwind_SetGR and pass that to RtlUnwindEx, so that later on the correct value is passed to the landing pad. The patch was tested for C++ and ObjC, the latter with both, the GNU libobjc runtime and my own. (With -O0, it still crashed and complained about invalid frames, but that is another issue.) I don't think this patch needs transfer of copyright, as it is small enoguh, so would it be possible to please include that in GCC 4.8.3? This would finally make ObjC usable on Windows again - and most likely other languages using exceptions as well. Thanks! PS: Please CC me as I'm not on the list! -- Jonathan --MP_/kTS6uvUb2+ZiLF.5APphCkV Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=gcc_seh.patch Content-length: 590 --- libgcc/unwind-seh.c.orig 2014-02-15 17:01:59.012396423 +0100 +++ libgcc/unwind-seh.c 2014-02-15 17:03:54.064755427 +0100 @@ -313,8 +313,9 @@ ms_exc->ExceptionInformation[3] = gcc_context.reg[1]; /* Begin phase 2. Perform the unwinding. */ - RtlUnwindEx (this_frame, gcc_context.ra, ms_exc, gcc_exc, - ms_orig_context, ms_disp->HistoryTable); + RtlUnwindEx (this_frame, gcc_context.ra, ms_exc, + (PVOID)gcc_context.reg[0], ms_orig_context, + ms_disp->HistoryTable); } /* In _Unwind_RaiseException we return _URC_FATAL_PHASE1_ERROR. */ --MP_/kTS6uvUb2+ZiLF.5APphCkV--