From owner-freebsd-toolchain@FreeBSD.ORG Mon Jan 21 04:49:23 2013 Return-Path: Delivered-To: toolchain@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 7843D13D; Mon, 21 Jan 2013 04:49:23 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id DCDE8968; Mon, 21 Jan 2013 04:49:22 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.6/8.14.6) with ESMTP id r0L4nD7W090780; Mon, 21 Jan 2013 06:49:13 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.7.4 kib.kiev.ua r0L4nD7W090780 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r0L4nCvs090779; Mon, 21 Jan 2013 06:49:12 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 21 Jan 2013 06:49:12 +0200 From: Konstantin Belousov To: Pedro Giffuni Subject: Re: standards/175453: Catching C++ std::bad_cast doesn't work in FreeBSD 9.1 Message-ID: <20130121044912.GE2522@kib.kiev.ua> References: <201301201652.r0KGq0d1042817@red.freebsd.org> <20130121014745.GD2522@kib.kiev.ua> <1358741301.62974.YahooMailNeo@web162102.mail.bf1.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="WeoCK3UN7lwjrlbw" Content-Disposition: inline In-Reply-To: <1358741301.62974.YahooMailNeo@web162102.mail.bf1.yahoo.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: "toolchain@freebsd.org" , Hongli Lai X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jan 2013 04:49:23 -0000 --WeoCK3UN7lwjrlbw Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Jan 20, 2013 at 08:08:21PM -0800, Pedro Giffuni wrote: >=20 >=20 >=20 >=20 > ----- Messaggio originale ----- > > Da: Konstantin Belousov=9A > >=20 > > On Sun, Jan 20, 2013 at 04:52:00PM +0000, Hongli Lai wrote: > >>=20 > >> >Number:=9A =9A =9A =9A 175453 > >> >Category:=9A =9A =9A standards > >> >Synopsis:=9A =9A =9A Catching C++ std::bad_cast doesn't work in Fre= eBSD=20 > > 9.1 > >> >Confidential:=9A no > >> >Severity:=9A =9A =9A non-critical > >> >Priority:=9A =9A =9A low > >> >Responsible:=9A =9A freebsd-standards > >> >State:=9A =9A =9A =9A =9A open > >> >Quarter:=9A =9A =9A =9A=20 > >> >Keywords:=9A =9A =9A=20 > >> >Date-Required: > >> >Class:=9A =9A =9A =9A =9A sw-bug > >> >Submitter-Id:=9A current-users > >> >Arrival-Date:=9A Sun Jan 20 17:00:00 UTC 2013 > >> >Closed-Date: > >> >Last-Modified: > >> >Originator:=9A =9A Hongli Lai > >> >Release:=9A =9A =9A =9A 9.1-RELEASE > >> >Organization: > >> Phusion > >> >Environment: > >> FreeBSD freebsd9 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Dec= =9A 4=20 > > 09:23:10 UTC 2012=9A =9A=20 > >> root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC=9A amd64 > >> >Description: > >> C++ code is not able to catch std::bad_cast exceptions, even though i= t=20 > > should. If a dynamic_cast is within a try-catch block, then that block = fails to=20 > > catch std::bad_cast, and the program crashes with an uncaught exception= as a=20 > > result. > >>=20 > >> I've attached a reproducible test case. You can also find it at=20 > > http://forums.freebsd.org/showthread.php?p=3D205804#post205804 and=20 > > http://stackoverflow.com/questions/14413703/why-does-catching-stdbad-ca= st-not-work-on-freebsd-9.=20 > > The code is compiled with the following GCC version: > >>=20 > >> $ gcc -v > >> Using built-in specs. > >> Target: amd64-undermydesk-freebsd > >> Configured with: FreeBSD/amd64 system compiler > >> Thread model: posix > >> gcc version 4.2.1 20070831 patched [FreeBSD] > >>=20 > >> FreeBSD 9.1 seems to be the only platform on which this bug appears. = The=20 > > code works as expected on Linux and OS X. According to a commenter, Fre= eBSD 9.0=20 > > works as expected too. According to another commenter the code fails on= FreeBSD=20 > > 9.1 with Clang too. > >> >How-To-Repeat: > >> See attached C++ program. > >> >Fix: > >>=20 > >>=20 > >> Patch attached with submission follows: > >>=20 > >> #include > >> #include > >> #include > >>=20 > >> class foo { > >> public: > >> =9A =9A virtual ~foo() {} > >> }; > >>=20 > >> class bar: public foo { > >> public: > >> =9A =9A int val; > >> =9A =9A bar(): val(123) {} > >> }; > >>=20 > >> static void > >> cast_test(const foo &f) { > >> =9A =9A try { > >> =9A =9A =9A =9A const bar &b =3D dynamic_cast(f); > >> =9A =9A =9A =9A printf("%d\n", b.val); > >> =9A =9A } catch (const std::bad_cast &) { > >> =9A =9A =9A =9A printf("bad cast\n"); > >> =9A =9A } > >> } > >>=20 > >> int main() { > >> =9A =9A foo f; > >> =9A =9A cast_test(f); > >> =9A =9A return 0; > >> } > >>=20 > > Confirmed, and it seems that the culprit is libstdc++. At least replaci= ng > > the system libstdc++.so.6 with the library from the stock build of gcc > > 4.7.2 (without touching libgcc_s.so.1) makes the catch operator working. > >=20 >=20 > Confirmed, > =9A > The problem is actually not in any of the code updates to libstdc++ but > in the way libstdc++ is configured/build since 9.0. >=20 > Reverting the changes in=9Astable/9/gnu/lib/libstdc up to r229037 things = work > just fine. >=20 > I suspect the culprit is r233749 and subsequent changes to build libstdc++ > as a filter library for libsupc++. >=20 > This also seems similar ot PR=9Akern/171610. Yes, quite possible. AFAIR, the 'catch' code compares the exception classes by the shared object ownership. It might get confused due to filter providi= ng some symbols. But I did not investigated the cause for real. --WeoCK3UN7lwjrlbw Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJQ/MjHAAoJEJDCuSvBvK1BJpIP+wTaJ6Eu6yTeD/q9YVt77ZTn +liyii4Gvv3jMtVdYwYGddjT/bMHlCik2WznEPBfbwQEUByOEJHEHPv5NVdDjQn3 MNI8CQtnUP/bu8tR4PrWPZyChbTYezge1RrDD8/ndxfMFdjyOUXgE5vHt9BgzwB8 Qf/4IxcY5TaantPUmjuAcpmmxxmVB9kGOSStcUZowJzsHlpVAOcwyvOxGz0Pw8m6 N3fDv0R23ldaEgsEX+++Haa3Ihp9nAVdPy0NzVv8MRbv7WoVfCl7ginxBPAL53wm IAdlHrLbpC4e105EHvNHG0nm9tqlOS0XlWjlZox6wb1Yat5X77iM1LCI4ZHDftcD 8Z8vEjx3poZ6srXQHpgw6djouQIQ6NycGbAmlIQdG5NNpNBitJP0cDvf+h9dGK9i nsVwjaQRz9iPdm7TdQeHdcr75HOVoIHkce+p9PRtW63QQtYT7xRFGrlgm7G9d3aM JZppvyMIWHh7e19VHtt7MptvAJv9oXe8KWTUJYK7FWE+fgxvPJY1wTnf+GHmBK8V HM3KHiTYwgVEBR4zXIYmwVjfMtVOZAnDZf9Glecv9PnZzEQQuYlzf1LOkSSFbaQ0 vHCdztBhY4tlbDpsIJwpW0sikgQve2a5e6Jrd/62vNI8g7Bmz2b/6sXXrNUxvhPi jg2De2GhZkl7eITqmNBO =irPx -----END PGP SIGNATURE----- --WeoCK3UN7lwjrlbw--