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>

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

[-- Attachment #1 --]
On Sun, Jan 20, 2013 at 08:08:21PM -0800, Pedro Giffuni wrote:
> 
> 
> 
> 
> ----- Messaggio originale -----
> > Da: Konstantin Belousovš
> > 
> > On Sun, Jan 20, 2013 at 04:52:00PM +0000, Hongli Lai wrote:
> >> 
> >>  >Number:š š š š  175453
> >>  >Category:š š š  standards
> >>  >Synopsis:š š š  Catching C++ std::bad_cast doesn't work in FreeBSD 
> > 9.1
> >>  >Confidential:š  no
> >>  >Severity:š š š  non-critical
> >>  >Priority:š š š  low
> >>  >Responsible:š š freebsd-standards
> >>  >State:š š š š š open
> >>  >Quarter:š š š š 
> >>  >Keywords:š š š 
> >>  >Date-Required:
> >>  >Class:š š š š š sw-bug
> >>  >Submitter-Id:š  current-users
> >>  >Arrival-Date:š  Sun Jan 20 17:00:00 UTC 2013
> >>  >Closed-Date:
> >>  >Last-Modified:
> >>  >Originator:š š  Hongli Lai
> >>  >Release:š š š š 9.1-RELEASE
> >>  >Organization:
> >>  Phusion
> >>  >Environment:
> >>  FreeBSD freebsd9 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Decš 4 
> > 09:23:10 UTC 2012š š 
> >>  root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERICš amd64
> >>  >Description:
> >>  C++ code is not able to catch std::bad_cast exceptions, even though it 
> > should. If a dynamic_cast is within a try-catch block, then that block fails to 
> > catch std::bad_cast, and the program crashes with an uncaught exception as a 
> > result.
> >> 
> >>  I've attached a reproducible test case. You can also find it at 
> > http://forums.freebsd.org/showthread.php?p=205804#post205804 and 
> > http://stackoverflow.com/questions/14413703/why-does-catching-stdbad-cast-not-work-on-freebsd-9. 
> > The code is compiled with the following GCC version:
> >> 
> >>  $ 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]
> >> 
> >>  FreeBSD 9.1 seems to be the only platform on which this bug appears. The 
> > code works as expected on Linux and OS X. According to a commenter, FreeBSD 9.0 
> > works as expected too. According to another commenter the code fails on FreeBSD 
> > 9.1 with Clang too.
> >>  >How-To-Repeat:
> >>  See attached C++ program.
> >>  >Fix:
> >> 
> >> 
> >>  Patch attached with submission follows:
> >> 
> >>  #include <exception>
> >>  #include <typeinfo>
> >>  #include <stdio.h>
> >> 
> >>  class foo {
> >>  public:
> >> š š  virtual ~foo() {}
> >>  };
> >> 
> >>  class bar: public foo {
> >>  public:
> >> š š  int val;
> >> š š  bar(): val(123) {}
> >>  };
> >> 
> >>  static void
> >>  cast_test(const foo &f) {
> >> š š  try {
> >> š š š š  const bar &b = dynamic_cast<const bar &>(f);
> >> š š š š  printf("%d\n", b.val);
> >> š š  } catch (const std::bad_cast &) {
> >> š š š š  printf("bad cast\n");
> >> š š  }
> >>  }
> >> 
> >>  int main() {
> >> š š  foo f;
> >> š š  cast_test(f);
> >> š š  return 0;
> >>  }
> >> 
> > Confirmed, and it seems that the culprit is libstdc++. At least replacing
> > 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.
> > 
> 
> Confirmed,
> š
> The problem is actually not in any of the code updates to libstdc++ but
> in the way libstdc++ is configured/build since 9.0.
> 
> Reverting the changes inšstable/9/gnu/lib/libstdc up to r229037 things work
> just fine.
> 
> I suspect the culprit is r233749 and subsequent changes to build libstdc++
> as a filter library for libsupc++.
> 
> This also seems similar ot PRškern/171610.

Yes, quite possible. AFAIR, the 'catch' code compares the exception classes
by the shared object ownership. It might get confused due to filter providing
some symbols.

But I did not investigated the cause for real.

[-- Attachment #2 --]
-----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-----
help

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