Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Jan 2013 06:49:12 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Pedro Giffuni <pfg@freebsd.org>
Cc:        "toolchain@freebsd.org" <toolchain@freebsd.org>, Hongli Lai <hongli@phusion.nl>
Subject:   Re: standards/175453: Catching C++ std::bad_cast doesn't work in FreeBSD 9.1
Message-ID:  <20130121044912.GE2522@kib.kiev.ua>
In-Reply-To: <1358741301.62974.YahooMailNeo@web162102.mail.bf1.yahoo.com>
References:  <201301201652.r0KGq0d1042817@red.freebsd.org> <20130121014745.GD2522@kib.kiev.ua> <1358741301.62974.YahooMailNeo@web162102.mail.bf1.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--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 <exception>
> >>  #include <typeinfo>
> >>  #include <stdio.h>
> >>=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<const bar &>(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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130121044912.GE2522>