From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9182 invoked by alias); 20 Mar 2008 15:28:31 -0000 Received: (qmail 9127 invoked by uid 22791); 20 Mar 2008 15:28:30 -0000 X-Spam-Check-By: sourceware.org Received: from rv-out-0910.google.com (HELO rv-out-0910.google.com) (209.85.198.187) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 20 Mar 2008 15:28:06 +0000 Received: by rv-out-0910.google.com with SMTP id g11so528183rvb.56 for ; Thu, 20 Mar 2008 08:28:05 -0700 (PDT) Received: by 10.140.203.9 with SMTP id a9mr798404rvg.288.1206026884992; Thu, 20 Mar 2008 08:28:04 -0700 (PDT) Received: by 10.141.50.3 with HTTP; Thu, 20 Mar 2008 08:28:04 -0700 (PDT) Message-ID: Date: Thu, 20 Mar 2008 15:28:00 -0000 From: "Shlom Marom" To: libstdc++@gcc.gnu.org, gcc@gnu.org, gcc-help@gcc.gnu.org, crossgcc@sourceware.org Subject: Exception handling on AIX5.3 with gcc 3.4.6 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_9396_10156203.1206026884973" Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-03/txt/msg00203.txt.bz2 ------=_Part_9396_10156203.1206026884973 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Content-length: 3546 Hi guys, I have some weird problem with exception handling on AIX (gcc 3.4.6 with AIX5.3), which I couldn't find any solution for in the web. ----------------------------- Problem description: ----------------------------- When throwing an exception of some derived object type, catch it, re-throw it and then try to catch it by the base object, the program gets segmentation fault instead of being caught by the relevant catch. BUT, please not to the weirdest problem: If I compiled the program with shared lib-gcc and with the pthread libstdc++ - everything works fine and also the base exception is being caught as it should. *Attached here a very small cpp file that contains a simple, for your convenient, although I will also paste the code in the email body=85 ----------------------------- The code: ----------------------------- #include void fun(void) { printf("in fun() - before throwing int...\n"); throw 1; } int main(void) { try { try { fun(); } catch(int i) { printf("catch int exception: %d, and re-throw...\n", i); throw; } } catch (...) { printf("the re-throw was caught...\n"); } return 0; } ---------------------------------------------------- Compilation (and link) commands: ---------------------------------------------------- Shared linking: gcc -o tester_shared main.cpp -pthread -I. -shared-libgcc -L/usr/lib -ldl -lpthread -lstdc++ Static linking: gcc -o tester_static main.cpp -L/usr/lib/threads -pthread -I. -static-libgcc -L/usr/lib -ldl -lpthread `gcc -print-file-name=3Dlibstdc++.a` -O *** `gcc -print-file-name=3Dlibstdc++.a` returns /usr/local/lib/gcc/powerpc-ibm-aix5.3.0.0/3.4.6/../../../libstdc++.a ---------------------------------------------------- Executables ldd output: ---------------------------------------------------- Shared linking: -------------------- $ldd ./tester_shared /usr/local/lib/gcc/powerpc-ibm-aix5.3.0.0/3.4.6/../../../libgcc_s_pthread.a= (shr.o) /usr/local/lib/gcc/powerpc-ibm-aix5.3.0.0/3.4.6/../../../pthread/libstdc++.= a(libstdc++.so.6) /usr/lib/libpthread.a(shr_xpg5.o) /usr/lib/libpthread.a(shr_comm.o) ./tester_shared /usr/lib/libcrypt.a(shr.o) /usr/lib/libc.a(shr.o) Static linking: -------------------- $ldd ./tester_static /usr/lib/libpthread.a(shr_xpg5.o) /usr/lib/libpthread.a(shr_comm.o) ./tester_static /usr/lib/libcrypt.a(shr.o) /usr/lib/libc.a(shr.o) ---------------------------------------------------- Executables output: ---------------------------------------------------- Shared linking: -------------------- in fun() - before throwing int... catch int exception: 1, and re-throw... the re-throw was caught... Static linking: -------------------- in fun() - before throwing int... catch int exception: 1, and re-throw... Segmentation fault (core dumped) ---------------------------------------------------- My purpose: ---------------------------------------------------- I need to find a way to fully support exception handling and statically link libgcc, since I don't want to distribute it with my libs and executables, as part of my products ---------------------------------------------------- Notes: ---------------------------------------------------- 1. The same problem happens when instead of re-throw int and catch (...) , you re-trow derived and catch base... 2. The same code works fine on other UNIX os, such as Linux (RHEL, Fedora, etc.=85) Thanks in advanced, Shlom Marom ------=_Part_9396_10156203.1206026884973 Content-Type: text/plain; name=minimal_main.cpp.cpp Content-Transfer-Encoding: base64 X-Attachment-Id: f_fe1gwomc0 Content-Disposition: attachment; filename=minimal_main.cpp.cpp Content-length: 627 I2luY2x1ZGUgPHN0ZGlvLmg+DQoNCnZvaWQgZnVuKHZvaWQpDQp7DQogICAg ICAgIHByaW50ZigiaW4gZnVuKCkgLSBiZWZvcmUgdGhyb3dpbmcgaW50Li4u XG4iKTsNCiAgICAgICAgdGhyb3cgMTsNCn0NCg0KaW50IG1haW4odm9pZCkN CnsNCiAgICB0cnkNCiAgICB7DQogICAgICAgIHRyeQ0KICAgICAgICB7DQog ICAgICAgICAgICAgICAgZnVuKCk7DQogICAgICAgIH0NCiAgICAgICAgY2F0 Y2goaW50IGkpDQogICAgICAgIHsNCiAgICAgICAgICAgICAgICBwcmludGYo ImNhdGNoIGludCBleGNlcHRpb246ICVkLCBhbmQgcmUtdGhyb3cuLi5cbiIs IGkpOw0KICAgICAgICAgICAgICAgIHRocm93Ow0KICAgICAgICB9DQogICAg fQ0KICAgIGNhdGNoICguLi4pDQogICAgew0KICAgICAgICBwcmludGYoInRo ZSByZS10aHJvdyB3YXMgY2F1Z2h0Li4uXG4iKTsNCiAgICB9DQogICAgcmV0 dXJuIDA7DQp9DQo= ------=_Part_9396_10156203.1206026884973--