This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: [BUG] try..catch does not work if compiled with clang 8.0
- From: Dominik Strasser <dominik dot strasser at onespin dot com>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Date: Wed, 18 Dec 2019 17:17:22 +0000
- Subject: Re: [BUG] try..catch does not work if compiled with clang 8.0
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=onespin.com; dmarc=pass action=none header.from=onespin.com; dkim=pass header.d=onespin.com; arc=none
- 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=UqwhRTqahofdhlwDDUH0DBze6Btn6pCnvLFX7zyoXZM=; b=RODSipdhRQEh7+24NLfRYFEAIQvBCrP370yspHMYIWLU0LInMN0cJarWaBLWhkRmnuTGRBcRvcmEeSDKnIoxg4E5SBl14oVTNydFpMnVNKHmeXAgIwrlp0N7b9gio8pD1wYi+GyMuFyaJt4EfNAoEJQ1NtOcAw1A7KMShN2JzZNQHzV7/uInmcBg0/LVOOjTF4tStOcEQVEgplScDiZthlAU/v5YgRIyFGlssAO0SCX1TOGeSVyCgq9fTDa1TQxfn14hsoSA9a05ErU2O+CWOzvBy8aBqM60bsg6JFFMnoe7WVFQ6mw5cjAASBHegl4mTAQnXnpVwn4JsNbLCUIidw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CQBxXNUMKiyLMTdOtBvSNc9aRjUZh1cgow5IbNlmjvcCbXVKXwP6D81Uwj9OWF6qmC1NAIQrcJes7WM+vUAE54hO5/NwPY6cjcCBfzTDRuZiIpAuLxqGwqxWcQo7hZXxtQK7cFkDuDpT4om8CimFvjuLdaAD6wtzcZydBe3lP6HRLd0Ow0k1h7IfRTfvN3UNL4ubc3uDVrYrc/CLEG/lndij1SsubQzPNMtmjvbujD7k+8stBRYc9yh5bcyXtauwUwyO6Cs4cGNYNJ2ldhSfsNzbxcGbH/TNV4/GET8v7mfH4tVl8NVdYoIAbFyqgpVev53lwKIscgOdNDpJlT9oxg==
- References: <CGME20191217093504eucas1p14cced4e1f9fcec50e44e9223d1761858@eucas1p1.samsung.com> <000701d5b4bd$42c086f0$c84194d0$@samsung.com> <af3cb99f-f1cc-3bcc-9644-310c259eb222@SystematicSw.ab.ca> <a9a62b50-688c-5747-266a-e7bb8157adbb@gmail.com> <b46cefcb-144b-50f8-1f79-d2879b4e4c25@SystematicSw.ab.ca> <016d01d5b5b5$47d6b8a0$d78429e0$@samsung.com>
Hi,
I am experiencing similar problems with my software. I am using Cygwin's
mingw g++.
The issue is very dependent on the files which are compiled, and how
they are compiled. (-Ox, -g, ...)
My suspicion is that the problem is with ld and the merging of the
exception region tables, but was never able to track down the issue.
However I cannot reproduce your issue on my machines. I tried:
GNU C++14 (GCC) version 7.4.0 (x86_64-pc-cygwin)
on a VM
CYGWIN_NT-6.1 xxx 2.11.2(0.329/5/3) 2018-11-08 14:34 x86_64 Cygwin
and
GNU C++14 (GCC) Version 7.4.0 (x86_64-pc-cygwin)
on my laptop
CYGWIN_NT-10.0 xxx 3.1.1(0.340/5/3) 2019-12-18 09:28 x86_64 Cygwin
with very different cygwin versions. Both of them give
./catch_test
std::exception: Error in reading no_such_file.bin
I tried my default compiler, too:
GNU C++14 (GCC) version 7.4.0 (x86_64-w64-mingw32)
No problems with this setup either.
Can you maybe post your binary so I could try it with this one.
Best regards
Dominik
Am 18.12.2019 um 16:10 schrieb Pavel Fedin:
> Well, it turned out more complicated than i thought. Here is the reduced reproducer:
> --- cut catch_test.cpp ---
> #include <stdexcept>
> #include <iostream>
> #include <vector>
> #include <string>
> #include <fstream>
>
> void from_file(const std::string &filepath, std::vector<int8_t> &data);
>
> int main()
> {
> try
> {
> std::vector<int8_t> data;
>
> from_file("no_such_file.bin", data);
> std::cout << "Success ???" << std::endl;
> }
> catch (const std::exception &e)
> {
> std::cout << "std::exception: " << e.what() << std::endl;
> }
>
> return 0;
> }
> --- cut catch_test.cpp ---
> --- cut catch_test_2.cpp ---
> #include <stdexcept>
> #include <iostream>
> #include <vector>
> #include <string>
> #include <fstream>
>
> using namespace std;
>
> template <typename T> void from_file_impl(const string &filepath, vector<T> &data)
> {
> // data.clear();
>
> std::ifstream ifs(filepath.c_str());
> if (ifs.rdstate() & ifstream::failbit)
> {
> throw std::runtime_error("Error in reading " + filepath);
> }
>
> /* T buffer;
>
> while (ifs.read(reinterpret_cast<char *>(&buffer), sizeof(T)))
> {
> data.push_back(buffer);
> }*/
> }
>
> void from_file(const string &filepath, vector<int8_t> &data) { from_file_impl(filepath, data); }
> --- cut catch_test_2.cpp ---
> --- cut console log ---
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ clang++-8 catch_test.cpp catch_test_2.cpp -g -o catch_test
>
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ ./catch_test
>
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ g++.exe catch_test.cpp catch_test_2.cpp -g -o catch_test
>
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ ./catch_test
>
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ clang++-5.0 catch_test.cpp catch_test_2.cpp -g -o catch_test
>
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $ ./catch_test
> std::exception: Error in reading no_such_file.bin
>
> CORP+p.fedin@P-FEDIN01 /cygdrive/d/Projects/Test
> $
> --- cut console log ---
>
> So, the problem actually reproduces with both clang 8 and gcc (7.4.0 on my system). clang 5 works fine.
>
> You could also be interested in strace (here is end of the output only, the beginning is quite long and not very interesting):
> --- cut ---
> 22301 238862 [main] catch_test 6078 seterrno_from_nt_status: /home/corinna/src/cygwin/cygwin-3.1.0/cygwin-3.1.0-1.x86_64/src/newlib-cygwin/winsup/cygwin/fhandler.cc:724 status 0xC0000034 -> windows error 2
> 75 238937 [main] catch_test 6078 geterrno_from_win_error: windows error 2 == errno 2
> 42 238979 [main] catch_test 6078 fhandler_base::open: 0xC0000034 = NtCreateFile (0x10, 0x80100000, \??\D:\Projects\Test\no_such_file.bin, io, NULL, 0x0, 0x7, 0x1, 0x4020, NULL, 0)
> 78 239057 [main] catch_test 6078 fhandler_base::open: 0 = fhandler_base::open(\??\D:\Projects\Test\no_such_file.bin, 0x108000)
> 41 239098 [main] catch_test 6078 fhandler_base::open_fs: 0 = fhandler_disk_file::open(\??\D:\Projects\Test\no_such_file.bin, 0x8000)
> 99 239197 [main] catch_test 6078 open: -1 = open(no_such_file.bin, 0x8000), errno 2
> --- Process 2620 (pid: 6078), exception 20474343 at 00007ff8c73fa388
> --- Process 2620 (pid: 6078) thread 12836 exited with status 0x20474343
> --- Process 2620 (pid: 6078) thread 3972 exited with status 0x20474343
> --- Process 2620 (pid: 6078) thread 15568 exited with status 0x20474343
> --- Process 2620 (pid: 6078) thread 5428 exited with status 0x20474343
> --- Process 2620 (pid: 6078) thread 2364 exited with status 0x20474343
> --- Process 2620 (pid: 6078) thread 16008 exited with status 0x20474343
> --- Process 2620 exited with status 0x20474343
> --- cut ---
> So, a Windows exception is reported, then the whole thing silently quits.
> I have an impression that it has to do with the bug i previously reported (and someone here claimed he could reproduce it)
>
> Kind regards,
> Pavel Fedin
> Senior Engineer
> Samsung Electronics Research center Russia
>
>
>> -----Original Message-----
>> From: cygwin-owner@cygwin.com [mailto:cygwin-owner@cygwin.com] On Behalf Of Brian Inglis
>> Sent: Wednesday, December 18, 2019 3:05 AM
>> To: cygwin@cygwin.com
>> Subject: Re: [BUG] try..catch does not work if compiled with clang 8.0
>>
>> On 2019-12-17 13:51, Csaba Ráduly wrote:
>>> On 17/12/2019 17:29, Brian Inglis wrote:
>>>> On 2019-12-17 02:35, Pavel Fedin wrote:
>>>>> I haven't upgraded for a while and today i finally decided to do so. After
>>>>> rebuilding by project with clang++ 8.0 i found out that try...catch construct
>>>>> doesn't work. The program just gets silently aborted.
>>>>> Switched back to old clang++ 5.0 and it works.
>>>>> Also an old bug which i reported some (a while) time ago persists: uncaught
>>>>> throw does not print anything.
>>>>> OS is Windows 10 x86/64.
>>>> It is unlikely that try/catch does not work in the general case for clang++8,
>>>> and your post has insufficient information to reproduce the problem.
>>> a.k.a. https://www.chiark.greenend.org.uk/~sgtatham/bugs.html#respect
>> Indeed!
>>> WJFFM
>>>> $ cat catcher.cpp
>>> #include <stdexcept>
>>> #include <iostream>
>>> int pitcher()
>>> {
>>> throw std::runtime_error{"Ouch"};
>>> }
>>> int main()
>>> {
>>> try {
>>> return pitcher();
>>> }
>>> catch (std::exception const&e) {
>>> std::cout << "Caught a " << typeid(e).name() << " - " << e.what() << '\n';
>>> return 42;
>>> }
>>> }
>>> $ g++ -v -Wall -Wpedantic -Wextra -g catcher.cpp
>>> $ ./a.exe
>>> Caught a St13runtime_error - Ouch
>> The report was about clang++ 8 vs 5; tweaked source to build under 5 and 8:
>> ...
>> #include <typeinfo>
>> int pitcher()
>> {
>> throw std::runtime_error("Ouch");
>> }
>> ...
>> but same WJFFM results:
>> $ clang++-5.0 -g -Og -Wpedantic -Wall -Wextra -o try-catch-stc{,.cpp}
>> $ ./try-catch-stc
>> Caught a St13runtime_error - Ouch
>> $ clang++-8 -g -Og -Wpedantic -Wall -Wextra -o try-catch-stc{,.cpp}
>> $ ./try-catch-stc
>> Caught a St13runtime_error - Ouch
>> --
>> Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada
>> This email may be disturbing to some readers as it contains
>> too much technical detail. Reader discretion is advised.
>> --
>> Problem reports: https://protect2.fireeye.com/url?k=b437d571-e9e489fe-b4365e3e-
>> 0cc47a31ce52-fd9c07d8a89a97f5&u=http://cygwin.com/problems.html
>> FAQ: https://protect2.fireeye.com/url?k=2e1da12d-73cefda2-2e1c2a62-
>> 0cc47a31ce52-67f7089b29388f59&u=http://cygwin.com/faq/
>> Documentation: https://protect2.fireeye.com/url?k=3f2aeb24-62f9b7ab-3f2b606b-
>> 0cc47a31ce52-9528889b998d683e&u=http://cygwin.com/docs.html
>> Unsubscribe info: https://protect2.fireeye.com/url?k=b1682add-ecbb7652-b169a192-
>> 0cc47a31ce52-e02defedfa7edb6b&u=http://cygwin.com/ml/#unsubscribe-simple
>
>
>
>
>
>
> --
> Problem reports: http://cygwin.com/problems.html
> FAQ: http://cygwin.com/faq/
> Documentation: http://cygwin.com/docs.html
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
>
--
Dominik Strasser | Phone: +49 89 99013-436
OneSpin Solutions GmbH | Fax: +49 89 99013-100
Nymphenburgerstr. 20a
80335 Muenchen | dominik.strasser@onespin.com
Geschaeftsfuehrung: Dr. Raik Brinkmann, Oliver Habeck
Vorsitzender des Beirats: Paul Hill
Sitz: Muenchen; Amtsgericht Muenchen HRB 139464
UstID#: DE 814413215