From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 9 17:03:00 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F2E33106566B for ; Wed, 9 Apr 2008 17:03:00 +0000 (UTC) (envelope-from yuri@rawbw.com) Received: from shell.rawbw.com (shell.rawbw.com [198.144.192.42]) by mx1.freebsd.org (Postfix) with ESMTP id C5E298FC1B for ; Wed, 9 Apr 2008 17:03:00 +0000 (UTC) (envelope-from yuri@rawbw.com) Received: from eagle.syrec.org (ip224.carlyle.sfo.ygnition.net [24.219.144.224]) (authenticated bits=0) by shell.rawbw.com (8.13.6/8.13.6) with ESMTP id m39GdBWl038705; Wed, 9 Apr 2008 09:39:11 -0700 (PDT) Message-ID: <47FCF12D.3070902@rawbw.com> Date: Wed, 09 Apr 2008 09:39:09 -0700 From: Yuri User-Agent: Thunderbird 2.0.0.12 (X11/20080312) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: C++ exceptions are broken in FreeBSD with gcc-compiled code? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: yuri@rawbw.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Apr 2008 17:03:01 -0000 I am unable to make a C++ program to catch an exception using the the system g++ compiler. > cat exc.C #include #include using namespace std; int main() { try { throw string("String"); } catch (string s) { cout << "Caught an exception \"" << s << "\"\n"; } } * Failed attempts with system compiler (using /lib/libgcc_s.so.1 and /usr/lib/libstdc++.so.6): > echo $LD_LIBRARY_PATH > g++ -fexceptions -o exc exc.C > exc Exception raised: Memory allocation failure! > g++ -pthread -fexceptions -o exc exc.C > exc Exception raised: Memory allocation failure! * Succeeded attempt with gcc-4.3.0 and -pthread option (using /usr/local/gcc-4.3.0/lib/libgcc_s.so.1 and /usr/local/gcc-4.3.0/lib/libstdc): > echo $LD_LIBRARY_PATH /usr/local/gcc-4.3.0/lib > /usr/local/gcc-4.3.0/bin/g++ -pthread -fexceptions -o exc exc.C > exc Caught an exception "String" * Failed attempt with gcc-4.3.0 without -pthread option (using /usr/local/gcc-4.3.0/lib/libgcc_s.so.1 and /usr/local/gcc-4.3.0/lib/libstdc): > echo $LD_LIBRARY_PATH /usr/local/gcc-4.3.0/lib > /usr/local/gcc-4.3.0/bin/g++ -fexceptions -o exc exc.C > exc Abort trap: 6 So exceptions *only* work with new gcc-4.3.0 and -pthread option. Is this a known issue? > g++ --version g++ (GCC) 4.2.1 20070719 [FreeBSD] > uname -a FreeBSD xxx.xxx.xxx 7.0-STABLE FreeBSD 7.0-STABLE #5: Thu Feb 28 03:58:20 PST 2008 yuri@xxx.xxx.xxx:/usr/obj/usr/src/sys/GENERIC i386 Yuri