From owner-freebsd-toolchain@FreeBSD.ORG Mon Jan 21 04:08:31 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 EDCC2883 for ; Mon, 21 Jan 2013 04:08:31 +0000 (UTC) (envelope-from giffunip@yahoo.com) Received: from nm5-vm0.bullet.mail.bf1.yahoo.com (nm5-vm0.bullet.mail.bf1.yahoo.com [98.139.213.150]) by mx1.freebsd.org (Postfix) with SMTP id 7B1E0857 for ; Mon, 21 Jan 2013 04:08:31 +0000 (UTC) Received: from [98.139.212.145] by nm5.bullet.mail.bf1.yahoo.com with NNFMP; 21 Jan 2013 04:08:22 -0000 Received: from [98.139.212.223] by tm2.bullet.mail.bf1.yahoo.com with NNFMP; 21 Jan 2013 04:08:22 -0000 Received: from [127.0.0.1] by omp1032.mail.bf1.yahoo.com with NNFMP; 21 Jan 2013 04:08:22 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 273789.36724.bm@omp1032.mail.bf1.yahoo.com Received: (qmail 75047 invoked by uid 60001); 21 Jan 2013 04:08:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1358741301; bh=/s7RwNFM9dbxqvq+0mpWxjJcO1X4IOWKF8pVcT75pyw=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-RocketYMMF:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=VAqRm6r2Uikm0R8aHr94LAPgoIUg3u+CEwz0Z+ng1Km2lMB8IDQNxTXxu7/rtMLUevqsXD1HQPtlmNGNZDnViilVaeqI7COI0R7Fens4d1Tjiou2/Pl8/k+PgjGQzOYJ8Ka/V+FFRrumBro1d5ZrIqq27lXs2oQ7CrqKwPTGkCc= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-RocketYMMF:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=fYd7fwzwgIg1aHk/IriTYaDePmXIPANEZOy5alIalRVuofbq9gTotoucWN5kiNHU+fFyhE8xZPh2I2tVBf68z6luyDDWFrF5eTJWizHQgbgu6JxEa9RIXGDxmM9Iym/xTRv6c/AD45+TieV/zv3W1I1UOxmbiqdJI3IbOqXATnE=; X-YMail-OSG: hK1K6X4VM1nkUwjPAo3InOJIdNIuvCVpZ5kIIGu49noMr2w GdSishLnukxtdr2Cj4RYVRVAGxM.3Lwgn16bfP.auzA.eOq3TyrB5Bx0mIEs zNJHx_yzCfRIaMd0APpJDkxVnIDkwktz60NqdHT5y5TZZS9l_WlSzEE6fzlf QRYuY.1oaNbyEAE5MYaFnhx6tcnw7qMYxxXvT6G8K67Qjoj4SNG3YRv7Y34T ZFAZivKzHCH2JgWJeGhMBjszNge1SdtcF3pxJD72OgBXQEy9qAkPSJNWejLK ogCZoMYZfD7ZQNm57SBDuElFcFgAgM3OiYw8_HXdkdS0fHKwEHWcJHrONCYi fZAEUmJcGuSzPvvKxn1B6Od9tyzagYA_63A1f74RjJ9BpeH0xTaE3qBn34h7 ltAdJT5LIVIecvMSIQ6.VKab.AIHLfWvvd2RTsgHY4hm3X82335wSZSXcv22 Am5Kdq1M55Syc2c5E6v9BC0uc6S3dt7Z8ScKZBSmmaHTrWiaZeZI6Xcxox1n YqLgZ9vNrXKTupgn2evxzCPTyvr2eNPe.DFf3Q0ENCklADLygs2aKP.bMwRc KVboiMT9icERY4ZG4sCzmWhPmXkOqP.6x02ihrS9u54R7ihX8o6TYmrYc_0t IgArbOmxmo3SpL6UV.N5eDVPEAqiTImGA4RCw4ZU3Y7gds5lVwKXywNWNzfY b4OvRpWxudI9rPvvD4sleaxhHCoJIN3E3NAw9D0Gb7J.wpTbNCALw9Grs.4x vpS5mRMmAhG1b6liSvtrbilPFCH4E Received: from [200.118.157.7] by web162102.mail.bf1.yahoo.com via HTTP; Sun, 20 Jan 2013 20:08:21 PST X-Rocket-MIMEInfo: 001.001, CgoKCi0tLS0tIE1lc3NhZ2dpbyBvcmlnaW5hbGUgLS0tLS0KPiBEYTogS29uc3RhbnRpbiBCZWxvdXNvdsKgCj4gCj4gT24gU3VuLCBKYW4gMjAsIDIwMTMgYXQgMDQ6NTI6MDBQTSArMDAwMCwgSG9uZ2xpIExhaSB3cm90ZToKPj4gCj4.ICA.TnVtYmVyOsKgIMKgIMKgIMKgICAxNzU0NTMKPj4gID5DYXRlZ29yeTrCoCDCoCDCoCAgc3RhbmRhcmRzCj4.ICA.U3lub3BzaXM6wqAgwqAgwqAgIENhdGNoaW5nIEMrKyBzdGQ6OmJhZF9jYXN0IGRvZXNuJ3Qgd29yayBpbiBGcmVlQlNEIAo.IDkuMQo.PiAgPkNvbmYBMAEBAQE- X-RocketYMMF: giffunip X-Mailer: YahooMailWebService/0.8.130.494 References: <201301201652.r0KGq0d1042817@red.freebsd.org> <20130121014745.GD2522@kib.kiev.ua> Message-ID: <1358741301.62974.YahooMailNeo@web162102.mail.bf1.yahoo.com> Date: Sun, 20 Jan 2013 20:08:21 -0800 (PST) From: Pedro Giffuni Subject: Re: standards/175453: Catching C++ std::bad_cast doesn't work in FreeBSD 9.1 To: Konstantin Belousov , Hongli Lai In-Reply-To: <20130121014745.GD2522@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "toolchain@freebsd.org" X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Pedro Giffuni 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:08:32 -0000 =0A=0A=0A=0A----- Messaggio originale -----=0A> Da: Konstantin Belousov=A0= =0A> =0A> On Sun, Jan 20, 2013 at 04:52:00PM +0000, Hongli Lai wrote:=0A>> = =0A>> >Number:=A0 =A0 =A0 =A0 175453=0A>> >Category:=A0 =A0 =A0 standar= ds=0A>> >Synopsis:=A0 =A0 =A0 Catching C++ std::bad_cast doesn't work in = FreeBSD =0A> 9.1=0A>> >Confidential:=A0 no=0A>> >Severity:=A0 =A0 =A0 n= on-critical=0A>> >Priority:=A0 =A0 =A0 low=0A>> >Responsible:=A0 =A0 fre= ebsd-standards=0A>> >State:=A0 =A0 =A0 =A0 =A0 open=0A>> >Quarter:=A0 =A0= =A0 =A0 =0A>> >Keywords:=A0 =A0 =A0 =0A>> >Date-Required:=0A>> >Class:= =A0 =A0 =A0 =A0 =A0 sw-bug=0A>> >Submitter-Id:=A0 current-users=0A>> >Ar= rival-Date:=A0 Sun Jan 20 17:00:00 UTC 2013=0A>> >Closed-Date:=0A>> >Las= t-Modified:=0A>> >Originator:=A0 =A0 Hongli Lai=0A>> >Release:=A0 =A0 = =A0 =A0 9.1-RELEASE=0A>> >Organization:=0A>> Phusion=0A>> >Environment:= =0A>> FreeBSD freebsd9 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Dec= =A0 4 =0A> 09:23:10 UTC 2012=A0 =A0 =0A>> root@farrell.cse.buffalo.edu:/us= r/obj/usr/src/sys/GENERIC=A0 amd64=0A>> >Description:=0A>> C++ code is no= t able to catch std::bad_cast exceptions, even though it =0A> should. If a = dynamic_cast is within a try-catch block, then that block fails to =0A> cat= ch std::bad_cast, and the program crashes with an uncaught exception as a = =0A> result.=0A>> =0A>> I've attached a reproducible test case. You can al= so find it at =0A> http://forums.freebsd.org/showthread.php?p=3D205804#post= 205804 and =0A> http://stackoverflow.com/questions/14413703/why-does-catchi= ng-stdbad-cast-not-work-on-freebsd-9. =0A> The code is compiled with the fo= llowing GCC version:=0A>> =0A>> $ gcc -v=0A>> Using built-in specs.=0A>> = Target: amd64-undermydesk-freebsd=0A>> Configured with: FreeBSD/amd64 sys= tem compiler=0A>> Thread model: posix=0A>> gcc version 4.2.1 20070831 pat= ched [FreeBSD]=0A>> =0A>> FreeBSD 9.1 seems to be the only platform on whi= ch this bug appears. The =0A> code works as expected on Linux and OS X. Acc= ording to a commenter, FreeBSD 9.0 =0A> works as expected too. According to= another commenter the code fails on FreeBSD =0A> 9.1 with Clang too.=0A>> = >How-To-Repeat:=0A>> See attached C++ program.=0A>> >Fix:=0A>> =0A>> =0A= >> Patch attached with submission follows:=0A>> =0A>> #include =0A>> #include =0A>> #include =0A>> =0A>> class foo = {=0A>> public:=0A>> =A0 =A0 virtual ~foo() {}=0A>> };=0A>> =0A>> class = bar: public foo {=0A>> public:=0A>> =A0 =A0 int val;=0A>> =A0 =A0 bar():= val(123) {}=0A>> };=0A>> =0A>> static void=0A>> cast_test(const foo &f)= {=0A>> =A0 =A0 try {=0A>> =A0 =A0 =A0 =A0 const bar &b =3D dynamic_cast<= const bar &>(f);=0A>> =A0 =A0 =A0 =A0 printf("%d\n", b.val);=0A>> =A0 =A0 = } catch (const std::bad_cast &) {=0A>> =A0 =A0 =A0 =A0 printf("bad cast\n= ");=0A>> =A0 =A0 }=0A>> }=0A>> =0A>> int main() {=0A>> =A0 =A0 foo f;= =0A>> =A0 =A0 cast_test(f);=0A>> =A0 =A0 return 0;=0A>> }=0A>> =0A> Conf= irmed, and it seems that the culprit is libstdc++. At least replacing=0A> t= he system libstdc++.so.6 with the library from the stock build of gcc=0A> 4= .7.2 (without touching libgcc_s.so.1) makes the catch operator working.=0A>= =0A=0AConfirmed,=0A=A0=0AThe problem is actually not in any of the code up= dates to libstdc++ but=0Ain the way libstdc++ is configured/build since 9.0= .=0A=0AReverting the changes in=A0stable/9/gnu/lib/libstdc up to r229037 th= ings work=0Ajust fine.=0A=0AI suspect the culprit is r233749 and subsequent= changes to build libstdc++=0Aas a filter library for libsupc++.=0A=0AThis = also seems similar ot PR=A0kern/171610.=0A=0APedro.