public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26397]  New: Program crashes when rethrowing exception
@ 2006-02-21 15:55 michael dot klein at fazi dot de
  2006-02-21 15:57 ` [Bug target/26397] " michael dot klein at fazi dot de
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: michael dot klein at fazi dot de @ 2006-02-21 15:55 UTC (permalink / raw)
  To: gcc-bugs

The program below crashes with illegal instruction when rethrowing the
previously caught exception.

GCC version:

$ powerpc-ibm-aix5.2.0.0-gcc-4.0.2 -v
Using built-in specs.
Target: powerpc-ibm-aix5.2.0.0
Configured with: ../gcc-4.0.2/configure --disable-nls --enable-threads=posix
--enable-languages=c,c++ --disable-shared
--enable-version-specific-runtime-libs 
Thread model: aix
gcc version 4.0.2

$ powerpc-ibm-aix5.2.0.0-gcc-4.0.2 exctest.cpp -lstdc++ -o exctest


#include <string>

struct FzException
{
  const char *what()
  {
    mWhat = std::string("a") + std::string("b");
    return mWhat.c_str();
  }

  std::string mWhat;
};


int main(int, char **argv)
{
  try
  {
    try
    {
      throw FzException();
    }
    catch(FzException & e)
    {
      e.what();
      throw;
    }
  }
  catch(...)
  {
    exit(1);
  }
}


-- 
           Summary: Program crashes when rethrowing exception
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: michael dot klein at fazi dot de
 GCC build triplet: powerpc-ibm-aix5.2.0.0
  GCC host triplet: powerpc-ibm-aix5.2.0.0
GCC target triplet: powerpc-ibm-aix5.2.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
@ 2006-02-21 15:57 ` michael dot klein at fazi dot de
  2006-02-21 16:05 ` pinskia at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: michael dot klein at fazi dot de @ 2006-02-21 15:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from michael dot klein at fazi dot de  2006-02-21 15:57 -------
Created an attachment (id=10887)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=10887&action=view)
Preprocessed source


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
  2006-02-21 15:57 ` [Bug target/26397] " michael dot klein at fazi dot de
@ 2006-02-21 16:05 ` pinskia at gcc dot gnu dot org
  2006-02-21 16:21 ` michael dot klein at fazi dot de
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-21 16:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-02-21 16:05 -------
$ powerpc-ibm-aix5.2.0.0-gcc-4.0.2 exctest.cpp -lstdc++ -o exctest

Can you try linking with:
$ powerpc-ibm-aix5.2.0.0-g++-4.0.2 exctest.cpp  -o exctest

instead and see if that helps?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
  2006-02-21 15:57 ` [Bug target/26397] " michael dot klein at fazi dot de
  2006-02-21 16:05 ` pinskia at gcc dot gnu dot org
@ 2006-02-21 16:21 ` michael dot klein at fazi dot de
  2006-04-14 17:52 ` dje at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: michael dot klein at fazi dot de @ 2006-02-21 16:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from michael dot klein at fazi dot de  2006-02-21 16:21 -------
Didn't help, same result with powerpc-ibm-aix5.2.0.0-g++ (there is no
powerpc-ibm-aix5.2.0.0-g++-4.0.2 here).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
                   ` (2 preceding siblings ...)
  2006-02-21 16:21 ` michael dot klein at fazi dot de
@ 2006-04-14 17:52 ` dje at gcc dot gnu dot org
  2006-04-24  9:26 ` michael dot klein at fazi dot de
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: dje at gcc dot gnu dot org @ 2006-04-14 17:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dje at gcc dot gnu dot org  2006-04-14 17:52 -------
The testcase works for me.  I am a little confused about what you actually have
installed if you have "gcc" and "g++" installed with different names (with and
without -4.0.2).  Do you have a consistent G++ installation or are you mixing
and matching different G++?  Somehow using different versions of the compiler
and libraries?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
                   ` (3 preceding siblings ...)
  2006-04-14 17:52 ` dje at gcc dot gnu dot org
@ 2006-04-24  9:26 ` michael dot klein at fazi dot de
  2006-06-07 23:14 ` mark dot woollard at macrovision dot com
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: michael dot klein at fazi dot de @ 2006-04-24  9:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from michael dot klein at fazi dot de  2006-04-24 09:26 -------
Actually, gcc is installed both with *and* without "-X.Y.Z" on all machines
here except the Debian Linuxes (AIX, HP-UX, Solaris), but none of them carries
a g++ ending with "-X.Y.Z".

According to truss, libstdc++.a and libgcc.a are definitely pulled from
/usr/local/lib/gcc/powerpc-ibm-aix5.2.0.0/4.0.2

Anyway, I just noticed something odd, the program works when:
- compiled and linked with 3.3.6
- compiled with 3.3.6, linked with 4.0.2
- compiled with 4.0.2, linked with 3.3.6

And the program only crashes if it is compiled *and* linked with 4.0.2. Any
reasonable explanation for this?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
                   ` (4 preceding siblings ...)
  2006-04-24  9:26 ` michael dot klein at fazi dot de
@ 2006-06-07 23:14 ` mark dot woollard at macrovision dot com
  2006-07-07 18:26 ` stuart dot downing at sungard dot com
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: mark dot woollard at macrovision dot com @ 2006-06-07 23:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from mark dot woollard at macrovision dot com  2006-06-07 23:13 -------
I have come across this issue too. It seems that if the exception being thrown
is passed back across a function call then the rethrow will cause a segfault.
If the catch and rethrow are in the same function as the original throw then
the issue does not reveal itself. Example code that causes the problem is below
and I have tested with this against compilers from 3.4.3 through to 4.1.1. The
same code behaves correctly on all other platforms we work with.

#include <iostream>
#include <string>
#include <exception>

class derived : public std::exception
{
public:
        derived( const std::string &m ) : msg(m) { }
        virtual ~derived() throw() {}

        const char *what() const throw()
        {
                return msg.c_str( );
        }       

private:
        std::string msg;
};

void test( )
{
        derived e("Screwed");
        throw e;
}

int main ( int argc, char * argv[] )
{
        try
        {
                try
                {
                        test( ); 
                        // Switching to the following in place of calling
test() works correctly
                        // derived e("Screwed"); throw e; 
                }
                catch( const std::exception &e )
                {               
                        std::cout << "Inner catch: " << e.what() << std::endl;
                        throw; // Segfaults
                }
        }
        catch( const std::exception & e )
        {
                std::cout << "Outer catch: " << e.what() << std::endl;
        }

        return 0;
}


-- 

mark dot woollard at macrovision dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mark dot woollard at
                   |                            |macrovision dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
                   ` (5 preceding siblings ...)
  2006-06-07 23:14 ` mark dot woollard at macrovision dot com
@ 2006-07-07 18:26 ` stuart dot downing at sungard dot com
  2006-07-07 18:28 ` stuart dot downing at sungard dot com
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: stuart dot downing at sungard dot com @ 2006-07-07 18:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from stuart dot downing at sungard dot com  2006-07-07 18:25 -------
Created an attachment (id=11852)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11852&action=view)
Sample code that exhibits segmentation fault

This is a simplified code sample that produces the symptom


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
                   ` (6 preceding siblings ...)
  2006-07-07 18:26 ` stuart dot downing at sungard dot com
@ 2006-07-07 18:28 ` stuart dot downing at sungard dot com
  2008-10-15 12:30 ` dje at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: stuart dot downing at sungard dot com @ 2006-07-07 18:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from stuart dot downing at sungard dot com  2006-07-07 18:28 -------
We are also observing this symptom, but only when gcc is configured with
--disable-shared.

This configuration...

/devp/src/bld/gcc4.1.1.s/usr/local/bin/g++ -v
Target: powerpc-ibm-aix5.1.0.0
Configured with: /devp/src/gcc-4.1.1/configure --enable-languages=c,c++
--disable-nls --disable-threads --disable-shared
Thread model: aix
gcc version 4.1.1

exhibits a segmentation fault

but this one

/devp/src/bld/gcc4.1.1/usr/local/bin/g++ -
Using built-in specs.
Target: powerpc-ibm-aix5.1.0.0
Configured with: /devp/src/gcc-4.1.1/configure --enable-languages=c,c++
--disable-nls --disable-threads --enable-shared
Thread model: aix
gcc version 4.1.1

does not.


-- 

stuart dot downing at sungard dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |stuart dot downing at
                   |                            |sungard dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
                   ` (7 preceding siblings ...)
  2006-07-07 18:28 ` stuart dot downing at sungard dot com
@ 2008-10-15 12:30 ` dje at gcc dot gnu dot org
  2008-10-15 13:45 ` stuart dot downing at sungard dot com
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: dje at gcc dot gnu dot org @ 2008-10-15 12:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from dje at gcc dot gnu dot org  2008-10-15 12:29 -------
Proper G++ exception handling requires shared libraries.


-- 

dje at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dje at gcc dot gnu dot org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
                   ` (8 preceding siblings ...)
  2008-10-15 12:30 ` dje at gcc dot gnu dot org
@ 2008-10-15 13:45 ` stuart dot downing at sungard dot com
  2008-10-15 15:36 ` dje at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: stuart dot downing at sungard dot com @ 2008-10-15 13:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from stuart dot downing at sungard dot com  2008-10-15 13:43 -------
(In reply to comment #9)
> Proper G++ exception handling requires shared libraries.
> 

Why?  This is not the case on other target platforms. 


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
                   ` (9 preceding siblings ...)
  2008-10-15 13:45 ` stuart dot downing at sungard dot com
@ 2008-10-15 15:36 ` dje at gcc dot gnu dot org
  2008-11-06 15:35 ` dje at gcc dot gnu dot org
  2009-06-10 11:46 ` jwakely dot gcc at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: dje at gcc dot gnu dot org @ 2008-10-15 15:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from dje at gcc dot gnu dot org  2008-10-15 15:34 -------
You can try manually linking the program with libsupc++.a as well:

http://codesynthesis.com/~boris/blog/2006/12/10/statically-linking-on-aix/


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
                   ` (10 preceding siblings ...)
  2008-10-15 15:36 ` dje at gcc dot gnu dot org
@ 2008-11-06 15:35 ` dje at gcc dot gnu dot org
  2009-06-10 11:46 ` jwakely dot gcc at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: dje at gcc dot gnu dot org @ 2008-11-06 15:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from dje at gcc dot gnu dot org  2008-11-06 15:34 -------
Subject: Bug 26397

Author: dje
Date: Thu Nov  6 15:32:40 2008
New Revision: 141646

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141646
Log:
        PR target/26397
        * config/rs6000/aix.h (LIBSTDCXX_STATIC): Define.

        cp/
        * g++spec.c (LIBSTDCXX_STATIC): New.
        (lang_spec_driver): Use LIBSTDCXX_STATIC when not shared_libgcc.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/aix.h
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/g++spec.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

* [Bug target/26397] Program crashes when rethrowing exception
  2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
                   ` (11 preceding siblings ...)
  2008-11-06 15:35 ` dje at gcc dot gnu dot org
@ 2009-06-10 11:46 ` jwakely dot gcc at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: jwakely dot gcc at gmail dot com @ 2009-06-10 11:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #13 from jwakely dot gcc at gmail dot com  2009-06-10 11:45 -------
(In reply to comment #12)
> Subject: Bug 26397
> 
> Author: dje
> Date: Thu Nov  6 15:32:40 2008
> New Revision: 141646
> 
> URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141646
> Log:
>         PR target/26397
>         * config/rs6000/aix.h (LIBSTDCXX_STATIC): Define.
> 
>         cp/
>         * g++spec.c (LIBSTDCXX_STATIC): New.
>         (lang_spec_driver): Use LIBSTDCXX_STATIC when not shared_libgcc.
> 
> Modified:
>     trunk/gcc/ChangeLog
>     trunk/gcc/config/rs6000/aix.h
>     trunk/gcc/cp/ChangeLog
>     trunk/gcc/cp/g++spec.c
> 

http://gcc.gnu.org/ml/gcc/2009-06/msg00231.html shows that the string "-lstdc++
-lsupc++" is passed to collect2 as a single argument via execvp, resulting in
an attempt to link to "libstdc++ -lsupc++" which is not valid.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26397


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

end of thread, other threads:[~2009-06-10 11:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-21 15:55 [Bug c++/26397] New: Program crashes when rethrowing exception michael dot klein at fazi dot de
2006-02-21 15:57 ` [Bug target/26397] " michael dot klein at fazi dot de
2006-02-21 16:05 ` pinskia at gcc dot gnu dot org
2006-02-21 16:21 ` michael dot klein at fazi dot de
2006-04-14 17:52 ` dje at gcc dot gnu dot org
2006-04-24  9:26 ` michael dot klein at fazi dot de
2006-06-07 23:14 ` mark dot woollard at macrovision dot com
2006-07-07 18:26 ` stuart dot downing at sungard dot com
2006-07-07 18:28 ` stuart dot downing at sungard dot com
2008-10-15 12:30 ` dje at gcc dot gnu dot org
2008-10-15 13:45 ` stuart dot downing at sungard dot com
2008-10-15 15:36 ` dje at gcc dot gnu dot org
2008-11-06 15:35 ` dje at gcc dot gnu dot org
2009-06-10 11:46 ` jwakely dot gcc at gmail dot com

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