public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Exception handling on AIX5.3 with gcc 3.4.6
@ 2008-03-20 15:28 Shlom Marom
  2008-03-20 16:36 ` Brian Dessent
  2008-03-20 17:23 ` David Edelsohn
  0 siblings, 2 replies; 7+ messages in thread
From: Shlom Marom @ 2008-03-20 15:28 UTC (permalink / raw)
  To: libstdc++, gcc, gcc-help, crossgcc

[-- Attachment #1: Type: text/plain, Size: 3654 bytes --]

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/../../../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.…)


Thanks in advanced,

Shlom Marom

[-- Attachment #2: minimal_main.cpp.cpp --]
[-- Type: text/plain, Size: 461 bytes --]

#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;
}

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-03-26  1:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-20 15:28 Exception handling on AIX5.3 with gcc 3.4.6 Shlom Marom
2008-03-20 16:36 ` Brian Dessent
2008-03-21 23:36   ` Shlom Marom
2008-03-22  3:26     ` Brian Dessent
2008-03-23  9:22       ` Shlom Marom
2008-03-26  1:26   ` Ian Lance Taylor
2008-03-20 17:23 ` David Edelsohn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).