delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2020/08/17/13:37:20

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7865A385042D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1597685798;
bh=yBXnvOcHn7vhquXP0jAGOVavBi6pffnQ5NIdUAewedQ=;
h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=VOXul3bhYsEBo3xxaa1ZaB/nIEzP6f8B8Xi+h6P/y2ImLtJ/NVFeqFnJfaVrty84n
7VfAHN8iMwC1JOD6fQpZddjifYf7jjMIBb3p9Gz/2aK/AM5BdZVJgqja/wk5tN3A+t
K9DLnxm75+JVYbTsznQ5EXCxKlHstc4O92u8k7o4=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7D48D3850423
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=iKKwBIpExRNE2kGAnHOuyCFCjF2udxYx9vcOozWl1gV9BxMsWoetDaRPWlOfCzCvHhnK/HSqbWjpcxuZmnelOVtOBgV7VfByui1+AG+l71fPY6LDMGAXsUtap7fIuXwTuHo4w8fn5Bn52vc9CEZjmcxE+D5zC/20CNIlT0Y45STYeMnOQezKHm6y+wcH7+zQVWhHYZdp5q7GMt0RLbS/EYYMX6iXkJels7xnaVqKqAnALcytE83HBlrdW1/eh8s8E1fJ8g0PoRJ6OqKREKTg2Z5LvMV6ciSMUwvq8Tsv4XzTNkVHRLaN1SRgh+ySwBcbl6mMUFWGHx6/u/Qhc/LbzQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=oahzOp6WLrVKTeIJPBdAZfep/WWA7p+k+XKegO4GIiY=;
b=gt4eYEADahR584jfvOYAkro1bRKFlCeokaZ6TapUwQborj6EyVpAT4bACO1X5SFjrKr65YIkf+xmCiHblAP7qKko60A0Ap2QjgxYp1mm5fGCcM7FaLOcz70pI14hJA3CPbKCRc5ynk82znbBWs5nUEMi0zdKTTeIUarBLtUhwOYy3KBVxiJSEzLREjQgO2LRyeu2xUrhki3GjgS7aRJQuDNf9Vc2QQ9Jzg+ihMrRxGR4s7LykWvZ/ITZmmvMR7Hm7U+EAZA4RhDEVoFhpgygBMTFJu8F525QjYZ7Ln9y5YSWGOj8yRMOg5jBIXrP0oUJLr8q2OLMbu65s9xi53N6hQ==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu;
dkim=pass header.d=cornell.edu; arc=none
Subject: [Attn: gcc maintainers] Re: unhandled C++ exceptions not propagating
To: cygwin AT cygwin DOT com
References: <vritk0xzfpk6 DOT fsf AT gmail DOT com>
<20200816125306 DOT 60dc246baf63d7f9fba60611 AT nifty DOT ne DOT jp>
<6c27d8d6-876a-6c09-bccd-a9123400cfdb AT cornell DOT edu>
<20200816225221 DOT d7c41334927c9766d6e26415 AT nifty DOT ne DOT jp>
<84a15cee-d772-4422-9cf0-1cec8d188cae AT cornell DOT edu>
<70f23307-6aaf-db8a-103e-81303350ffec AT cornell DOT edu>
Message-ID: <9525d8c2-74af-5c04-8a04-d84df4b1f2ef@cornell.edu>
Date: Mon, 17 Aug 2020 13:36:24 -0400
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101
Thunderbird/68.11.0
In-Reply-To: <70f23307-6aaf-db8a-103e-81303350ffec@cornell.edu>
X-ClientProxiedBy: MN2PR11CA0016.namprd11.prod.outlook.com
(2603:10b6:208:23b::21) To MN2PR04MB6176.namprd04.prod.outlook.com
(2603:10b6:208:e3::13)
MIME-Version: 1.0
X-MS-Exchange-MessageSentRepresentingType: 1
X-Originating-IP: [2604:6000:b407:7f00:6ddb:1b9b:deef:3580]
X-MS-PublicTrafficType: Email
X-MS-Office365-Filtering-Correlation-Id: 01bcb2e0-e977-4cec-aade-08d842d4114d
X-MS-TrafficTypeDiagnostic: MN2PR04MB6256:
X-Microsoft-Antispam-PRVS: <MN2PR04MB6256CD9EAEACF9799FB4E9EAD85F0 AT MN2PR04MB6256 DOT namprd04 DOT prod DOT outlook DOT com>
X-MS-Oob-TLC-OOBClassifiers: OLM:4125;
X-MS-Exchange-SenderADCheck: 1
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: J0jtC8ySM54CI5ugbLNePCscsFWgt/0mDsTwUom0s2in+8CNts7Q/5ajWfvNSNqUl+05tRWENXADkCRJmCLizrA3O7kpLUjwikhYohzGeuYOpSy+qsjNWNTGixko7T2ifc3/q66TrXZTPuNbde40ky1j+9sgVN+I2AGBKpndgP+kabFiSm/0Zg2zq/yrjqtInZOzqnZj/Es+13Povg9aAcM7Vw2mJdek4Xt7SK/VW6rPbz3iTqj2MSTlDyol/X5jcSmUM2yI3Pgr2rHji1fJ5GN67lqWi0YeOQ8n+fC3dp+12hC128Qh5Ifi8n0jM2URrCpKOACy6Se/HUgoZxKkQxAha5QtN4wN1l+wq/r3gk0Kp/qSWgwOffdOO93pAZNJqhSfUbN+fkP0yVpcB8BY2/uyQs5Y8vBKPOQ5vKSh9VNq3OaTx5AcbEjybNREgh+CSf4ZHIE+sbVNF7Ao9LOP1A==
X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:MN2PR04MB6176.namprd04.prod.outlook.com; PTR:; CAT:NONE;
SFS:(4636009)(366004)(376002)(346002)(396003)(39860400002)(136003)(966005)(75432002)(478600001)(6486002)(6916009)(53546011)(31686004)(186003)(52116002)(2906002)(8936002)(16526019)(36756003)(19627235002)(66476007)(66946007)(66574015)(2616005)(31696002)(83380400001)(86362001)(786003)(316002)(8676002)(66556008)(5660300002)(43740500002);
DIR:OUT; SFP:1102;
X-MS-Exchange-AntiSpam-MessageData: 2QUzxUFJb6QeLEuxM8jjd2FBD+jMj97K504CbRyU0gtc23CpW1DBBESjuzoKJ7E1CeZyYemwZ8wtzdp8toUwXz3PCaOGjlIExycPbL75USSPIKJRrbZT2iSIdJVQVALXI7jy1PjAUZXflti8DlOEdwyX0toq7Hw89Pje6e2KtQhEaSEbw2i5IaGxrAt+7epzVsKQdJBpnHVPi6/ttl5f3iFTJxPlbn69o0Ki/rBpprim8kIBp/6AoDpQo59cAnu8TbM6mFaX36IFQsGNOQOP5zxMINAcTZmE7Fm3zQ7kDhubD0bBULW+Aid9p+kmjaB79hwUozTjX34rmgCpS4qFsCKigYtx9oyqtRuVpR6kzHp/MXczSqKNM2DemkPcWkn/rJwFuJDyN9URc+ZjP41l/UzgLMXywccC+xhEyFkszYQBazNxlRo29ckcjJFLdHmSplgy53+r1LZkWX+DLh1QbpucQ4bTfHIrzArEyRyNBB8YvlHX7v6wxVFaifuKLEzJ51xXsutO/NSx0MLfh4NXx0bl49SDCIeItK0W7FDLM2b8d6PKj+tqLq/wfO7S+aMIrqimZnTy9yu8g55CJLCHey328Mad0cqAez3ENzy16QbIRYqEYXrhA/4EIq3Ix7XnoIwvnuTnKHlOevtOd87u+cx3bAGlSO7yAmqvfm74WtZqloqJNrESxV3rIAMuqxNEQbx0mR8KDW9H5PTY8uA7SQ==
X-OriginatorOrg: cornell.edu
X-MS-Exchange-CrossTenant-Network-Message-Id: 01bcb2e0-e977-4cec-aade-08d842d4114d
X-MS-Exchange-CrossTenant-AuthSource: MN2PR04MB6176.namprd04.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2020 17:36:26.5077 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 5d7e4366-1b9b-45cf-8e79-b14b27df46e1
X-MS-Exchange-CrossTenant-MailboxType: HOSTED
X-MS-Exchange-CrossTenant-UserPrincipalName: NTMM5BsuRjju1ofDwOXlnB8OPkSGgLHHIzqd54TLGzmIpexwnRv2zFpvgI8dDBYe6VhELfbnjc9J1qq+B5sGaw==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR04MB6256
X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, DKIM_INVALID,
DKIM_SIGNED, KAM_DMARC_STATUS, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE,
RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS,
TXREP autolearn=no autolearn_force=no version=3.4.2
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Ken Brown via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Ken Brown <kbrown AT cornell DOT edu>
Errors-To: cygwin-bounces AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces AT cygwin DOT com>
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id 07HHb1LZ017444

On 8/16/2020 6:38 PM, Ken Brown via Cygwin wrote:
> On 8/16/2020 10:56 AM, Ken Brown via Cygwin wrote:
>> On 8/16/2020 9:52 AM, Takashi Yano via Cygwin wrote:
>>> On Sun, 16 Aug 2020 09:21:24 -0400
>>> Ken Brown via Cygwin <cygwin AT cygwin DOT com> wrote:
>>>> On 8/15/2020 11:53 PM, Takashi Yano via Cygwin wrote:
>>>>> On Sat, 15 Aug 2020 20:38:01 -0300
>>>>> David McFarland via Cygwin <cygwin AT cygwin DOT com> wrote:
>>>>>>
>>>>>> I was just debugging a c++ app (b2 build system from boost), and noticed
>>>>>> that it would appear to exit unexpectedly without an error.  This turned
>>>>>> out to be when an unhandled C++ exception was thrown.
>>>>>>
>>>>>> On a fresh install of cygwin with gcc-g++, this program will throw an
>>>>>> exception from the std::string constructor:
>>>>>>
>>>>>> c++ -x c++ - <<END
>>>>>> #include <string>
>>>>>> int main() { std::string str(nullptr); return 0; }
>>>>>> END
>>>>>>
>>>>>> When it's executed from the shell it returns zero, but execution stops
>>>>>> at the exception.
>>>>>>
>>>>>> $ ./a; echo $?
>>>>>> 0
>>>>>>
>>>>>> When executed under gdb, the exception is caught, and the process exits
>>>>>> non-zero when continued:
>>>>>>
>>>>>> (gdb) r
>>>>>> Starting program: /home/corngood/a
>>>>>> [New Thread 4300.0x1390]
>>>>>> [New Thread 4300.0x1d24]
>>>>>> [New Thread 4300.0x1d48]
>>>>>> [New Thread 4300.0x80c]
>>>>>> gdb: unknown target exception 0x20474343 at 0x7ff8d2cfa799
>>>>>> Thread 1 "a" received signal ?, Unknown signal.
>>>>>> 0x00007ff8d2cfa799 in RaiseException () from 
>>>>>> /cygdrive/c/WINDOWS/System32/KERNELBASE.dll
>>>>>> (gdb) c
>>>>>> Continuing.
>>>>>> [Thread 4300.0x1d24 exited with code 541541187]
>>>>>> [Thread 4300.0x1870 exited with code 541541187]
>>>>>> [Thread 4300.0x1d48 exited with code 541541187]
>>>>>> [Thread 4300.0x1390 exited with code 541541187]
>>>>>> [Inferior 1 (process 4300) exited with code 04021641503]
>>>>>> (gdb)
>>>>>>
>>>>>> When executed under strace, it exits with an error as expected:
>>>>>>
>>>>>> $ strace -o /dev/null a; echo $?
>>>>>> 67
>>>>>>
>>>>>> That's as far as I've investigated so far.
>>>>>
>>>>> Is this the same issue with
>>>>> https://cygwin.com/pipermail/cygwin/2019-October/242795.html ?
>>>>>
>>>>> As far as I tested, this does not occur in 32-bit cygwin.
>>>>
>>>> This doesn't seem to be a new issue.  I found the following report from 6 years
>>>> ago, on Cygwin 1.7.30 with GCC 4.9.0:
>>>>
>>>> https://stackoverflow.com/questions/24402412/program-executed-on-cygwin-does-not-report-a-thrown-exception 
>>>>
>>>
>>> Thanks for the information. But I still wonder why 32-bit and 64-bit
>>> cygwin behave differently.
>>
>> I'm no C++ expert, but my understanding after a brief internet search is that 
>> an uncaught exception is supposed to cause std::terminate to be called.  So I 
>> installed gcc-debuginfo and ran the OP's test case under gdb with a breakpoint 
>> at 'terminate'.  On 32-bit Cygwin I got the expected behavior:
>>
>> Thread 1 "exception_test" hit Breakpoint 1, std::terminate ()
>>      at /usr/src/debug/gcc-9.3.0-2/libstdc++-v3/libsupc++/eh_terminate.cc:96
>> 96        __atomic_load (&__terminate_handler, &func, __ATOMIC_ACQUIRE);
>> (gdb) bt
>> #0  std::terminate ()
>>      at /usr/src/debug/gcc-9.3.0-2/libstdc++-v3/libsupc++/eh_terminate.cc:96
>> #1  0x57c45909 in __cxxabiv1::__cxa_throw (obj=obj AT entry=0x800396e8,
>>      tinfo=tinfo AT entry=0x57c646a8 <typeinfo for std::logic_error>,
>>      dest=0x57be6c60 <std::logic_error::~logic_error()>)
>>      at /usr/src/debug/gcc-9.3.0-2/libstdc++-v3/libsupc++/eh_throw.cc:95
>> #2  0x57c49223 in std::__throw_logic_error (
>>      __s=__s AT entry=0x57c60160 <cplus_demangle_builtin_types+10272> 
>> "basic_string::
>> _S_construct null not valid")
>>      at /usr/src/debug/gcc-9.3.0-2/libstdc++-v3/src/c++11/functexcept.cc:66
>> [...]
>>
>> On 64-bit Cygwin, however, I got the behavior reported by the OP:
>>
>> gdb: unknown target exception 0x20474343 at 0x7ff8cccca719
>>
>> Thread 1 "exception_test" received signal ?, Unknown signal.
>> 0x00007ff8cccca719 in RaiseException () from /c/WINDOWS/System32/KERNELBASE.dll
>> (gdb) c
>> Continuing.
>> [Thread 4508.0x3e20 exited with code 541541187]
>> [Thread 4508.0x5bc exited with code 541541187]
>> [Thread 4508.0x5ee8 exited with code 541541187]
>> [Thread 4508.0x1cd0 exited with code 541541187]
>> [Inferior 1 (process 4508) exited with code 04021641503]
>>
>> Note that the breakpoint at 'terminate' is not reached.  I tried putting a 
>> breakpoint at __cxa_throw and stepping through from there, but I don't really 
>> understand what's going on.  Someone who knows the innards of exception 
>> handling will have to look at this.
> 
> One further comment, and then I'll shut up

I lied.

> and leave it to people who know what 
> they're talking about: In the 64-bit case, the function _Unwind_RaiseException 
> in libgcc/unwind-seh.c gets called, and it calls the Win32 function 
> RaiseException as follows:
> 
>    RaiseException (STATUS_GCC_THROW, 0, 1, (ULONG_PTR *)&exc);
> 
> Then the following comment appears:
> 
>    /* The exception handler installed in crt0 will continue any GCC
>       exception that reaches there (and isn't marked non-continuable).
>       Returning allows the C++ runtime to call std::terminate.  */
> 
> Apparently this doesn't actually happen.

I'm beginning to think this is a bug in the Cygwin build of gcc.  The file 
unwind-seh.c is compiled on 64-bit Cygwin because __SEH__ is defined.  But it 
makes assumptions, such as those in the comment quoted above, that are not valid 
on Cygwin.

In fact, if you look at the main exception handler on Cygwin 
(exceptions.cc:626), it is clear that the exception code STATUS_GCC_THROW does 
not lead to continuation.  It falls under the default case:

     default:
       /* If we don't recognize the exception, we have to assume that
	 we are doing structured exception handling, and we let
	 something else handle it.  */
       return ExceptionContinueSearch;

[STATUS_GCC_THROW is 0x20474343, which shows up in the gdb output above as an 
unknown target exception.]

So it seems to me that either Cygwin's exception handler has to learn to handle 
the exception codes defined in unwind-seh.c, or else gcc should be built with 
__SEH__ undefined.

JonY, Achim, Corinna, am I missing something?

Ken
--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019