List Info

Thread: Exception handling on AIX5.3 with gcc 3.4.6




Exception handling on AIX5.3 with gcc 3.4.6
user name
2008-03-20 10:28:04
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…

-----------------------------
The code:
-----------------------------
#include <stdio.h>
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=libstdc++.a` -O
*** `gcc -print-file-name=libstdc++.a` returns
/usr/local/lib/gcc/powerpc-ibm-aix5.3.0.0/3.4.6/../../../lib
stdc++.a

----------------------------------------------------
Executables ldd output:
----------------------------------------------------
Shared linking:
--------------------
$ldd ./tester_shared
/usr/local/lib/gcc/powerpc-ibm-aix5.3.0.0/3.4.6/../../../lib
gcc_s_pthread.a(shr.o)
/usr/local/lib/gcc/powerpc-ibm-aix5.3.0.0/3.4.6/../../../pth
read/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.…)


Thanks in advanced,

Shlom Marom

--
For unsubscribe information see http://sourcewar
e.org/lists.html#faq
  
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )