Date: Sun, 20 Jan 2013 20:08:21 -0800 (PST) From: Pedro Giffuni <pfg@freebsd.org> To: Konstantin Belousov <kostikbel@gmail.com>, Hongli Lai <hongli@phusion.nl> Cc: "toolchain@freebsd.org" <toolchain@freebsd.org> Subject: Re: standards/175453: Catching C++ std::bad_cast doesn't work in FreeBSD 9.1 Message-ID: <1358741301.62974.YahooMailNeo@web162102.mail.bf1.yahoo.com> In-Reply-To: <20130121014745.GD2522@kib.kiev.ua> References: <201301201652.r0KGq0d1042817@red.freebsd.org> <20130121014745.GD2522@kib.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
=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 <exception= >=0A>> #include <typeinfo>=0A>> #include <stdio.h>=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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1358741301.62974.YahooMailNeo>