Subject: port-i386/9110: Exceptions caught within a shared library fail
To: None <gnats-bugs@gnats.netbsd.org>
From: None <crvich@us.ibm.com>
List: netbsd-bugs
Date: 01/03/2000 11:03:48
>Number:         9110
>Category:       port-i386
>Synopsis:       Exceptions caught within a shared library fail
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    port-i386-maintainer (NetBSD/i386 Portmaster)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jan  3 11:03:00 2000
>Last-Modified:
>Originator:     Ernest Crvich
>Organization:
IBM
>Release:        1.3.3 and 1.4.1
>Environment:
1.3.3:
NetBSD  1.3.3 NetBSD 1.3.3 (GENERIC) #0: Fri Dec 11 16:21:49 PST 1998     root@struis:/usr/src/sys/arch/i386/compile/GENERIC i386

1.4.1:
NetBSD  1.4.1 NetBSD 1.4.1 (GENERIC) #1: Tue Aug 10 00:03:09 MEST 1999     fvdl@struis:/usr/src/sys/arch/i386/compile/GENERIC i386

>Description:
Exceptions thrown within shared library code that are also caught within
that library cause various types of havoc (bus errors, segmentation
faults, corrupt data, etc.).  For example, one cannot use the exception
variable from the catch clause, nor can one rethrow a new exception.

Exceptions thrown within the shared library can be successfully caught
in the exe, however...the problem only arises when the library code
catches its own exceptions.
>How-To-Repeat:
I use egcs 1.1.2 on NetBSD 1.3.3, and the built-in egcs 1.1.1 on NetBSD
1.4.1.  In both cases, the built-in assembler and linker are used.

/*** foo.cpp: code for shared lib ***/
/* compile with "g++ -fPIC -c foo.cpp" */
/* link with "g++ -o libfoo.so.0.0 -shared foo.o" */
/* (under 1.3.3, must use egcs 1.1.2 and either fix */
/* the specs file or link with ld) */
#include <iostream.h>

int foo()
{
  int i = 42;
  try
  {
    throw i;
  }
  catch (const int &e)
  {
    cerr << "EXCEPTION: " << e << endl;  // generates memory fault
    return 1;
  }
  return 0;
}


/*** main.cpp: code for exe ***/
/* compile with "g++ -c main.cpp" */
/* link with "g++ -o main main.o -L. -lfoo" */
/* (under 1.3.3, must use egcs 1.1.2 and either fix */
/* the specs file or link with ld) */
extern int foo();
int main()
{
  return foo();
}

Run this test with the command "LD_LIBRARY_PATH=. ./main"
>Fix:
We've found no fix other than using static/archive libraries instead of
shared libraries.  We need to be able to catch exceptions in our library,
so we cannot change our source code.
>Audit-Trail:
>Unformatted: