public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Throw/Catch not working in SO?
@ 2002-10-15  2:45 Rob
  0 siblings, 0 replies; 5+ messages in thread
From: Rob @ 2002-10-15  2:45 UTC (permalink / raw)
  To: ckim; +Cc: gcc

This might be a manifestation of a problem involving different versions of the c++ support library, which includes functions used for internal run-time type identification and exception handling. If your main app is linked against one version of the support library and your shared library is linked against another, then Weird Stuff can happen.
Reported manifestations include exceptions not being caught, or SEGVs during the initial throw.

The simple solution is to just make sure the app and the lib are linked against the same version of the library (and, presumably, are built with the same C++ compiler). Unfortunately, not all of us have that luxury.

It seems to me that statically linking the support library into the shared object and then privatizing all the symbols should avoid these kinds of conflicts (and should prevent C++ ABI fragility, if the shared lib uses only a C interface), but I have been unable to get this to work. I'm still trying to figure out just what ld.so is doing to screw things up...

Hope this helps.

-rob

> -----Original Message-----
> From: Charles Y. Kim [mailto:ckim@telcontar.com]
> Sent: 14 October 2002 23:38
> To: gcc@gcc.gnu.org
> Subject: Throw/Catch not working in SO?
> 
> 
> Hi all,
> 
> I'm using some exception handling in a shared object, and while the
> throw()/catch() works in both Windows and FreeBSD (using GCC 
> 2.96), in Linux
> (GCC 3.02 --enable-shared --enable-threads=posix) the throw 
> is executed, and
> the catch never happens.
> 
> For example... let's say I have the following code in the 
> shared object...
> 
> void error() {
> 	throw(1);
> }
> 
> void error2() {
> 	error();
> }
> 
> void function() {
> 	try {
> 		if (blah)
> 			error2();
> 	}
> 	catch(...) {
> 		printf("exception caught");
> 	}
> }
> 
> I know that error2() is being called and the exception is 
> being thrown...
> but it's not being caught at all.
> 
> Does anyone have ANY ideas?
> 
> Thanks.
> 
> - Charles
> 
> 
> 

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

* Re: Throw/Catch not working in SO?
  2002-10-14 18:39   ` Charles Y. Kim
@ 2002-10-14 21:14     ` Fergus Henderson
  0 siblings, 0 replies; 5+ messages in thread
From: Fergus Henderson @ 2002-10-14 21:14 UTC (permalink / raw)
  To: Charles Y. Kim; +Cc: 'Janis Johnson', gcc

On 14-Oct-2002, Charles Y. Kim <ckim@telcontar.com> wrote:
> Good points Janis.  Here are a few answers.

You still didn't provide a complete example.

I suggest attaching a cut-down but complete set of source files,
together with a Makefile, that demonstrates the problem.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

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

* RE: Throw/Catch not working in SO?
  2002-10-14 18:38 ` Janis Johnson
@ 2002-10-14 18:39   ` Charles Y. Kim
  2002-10-14 21:14     ` Fergus Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Charles Y. Kim @ 2002-10-14 18:39 UTC (permalink / raw)
  To: 'Janis Johnson'; +Cc: gcc

Good points Janis.  Here are a few answers.

I've tried building the SO with the -fPIC flag.  The shared object is being
built with "g++ -shared".

Do I have to do something special when I open up the SO with dlopen?  I've
tried using dlopen("...", RTLD_NOW/LAZY || RTLD_GLOBAL) and those don't seem
to do anything either.  I've added -Wl,-E to the link line as well, but to
no avail.

This works in other platforms... I'm just stumped as to why it might not
work with Linux.  Also, this is a multithreaded app, and the actual SO is
FAR more complex than the code sample below.

I can see that throw is being called because I've checked out the stack
trace in GDB.

- Charles



-----Original Message-----
From: Janis Johnson [mailto:janis187@us.ibm.com]
Sent: Monday, October 14, 2002 5:16 PM
To: Charles Y. Kim
Cc: gcc@gcc.gnu.org
Subject: Re: Throw/Catch not working in SO?


On Mon, Oct 14, 2002 at 03:37:40PM -0700, Charles Y. Kim wrote:
> Hi all,
>
> I'm using some exception handling in a shared object, and while the
> throw()/catch() works in both Windows and FreeBSD (using GCC 2.96), in
Linux
> (GCC 3.02 --enable-shared --enable-threads=posix) the throw is executed,
and
> the catch never happens.
>
> For example... let's say I have the following code in the shared object...
>
> void error() {
> 	throw(1);
> }
>
> void error2() {
> 	error();
> }
>
> void function() {
> 	try {
> 		if (blah)
> 			error2();
> 	}
> 	catch(...) {
> 		printf("exception caught");
> 	}
> }
>
> I know that error2() is being called and the exception is being thrown...
> but it's not being caught at all.
>
> Does anyone have ANY ideas?

It works fine for me with GCC 3.0.4 on i686-pc-linux-gnu, but I
can't tell what I might have done differently.

Your code fragment isn't complete (it can't be compiled without
additional code added), and you don't say how you built your shared
object or how you know that error2 was called.  If you provide a
complete example, someone might be able to help.

Janis

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

* Re: Throw/Catch not working in SO?
  2002-10-14 17:36 Charles Y. Kim
@ 2002-10-14 18:38 ` Janis Johnson
  2002-10-14 18:39   ` Charles Y. Kim
  0 siblings, 1 reply; 5+ messages in thread
From: Janis Johnson @ 2002-10-14 18:38 UTC (permalink / raw)
  To: Charles Y. Kim; +Cc: gcc

On Mon, Oct 14, 2002 at 03:37:40PM -0700, Charles Y. Kim wrote:
> Hi all,
> 
> I'm using some exception handling in a shared object, and while the
> throw()/catch() works in both Windows and FreeBSD (using GCC 2.96), in Linux
> (GCC 3.02 --enable-shared --enable-threads=posix) the throw is executed, and
> the catch never happens.
> 
> For example... let's say I have the following code in the shared object...
> 
> void error() {
> 	throw(1);
> }
> 
> void error2() {
> 	error();
> }
> 
> void function() {
> 	try {
> 		if (blah)
> 			error2();
> 	}
> 	catch(...) {
> 		printf("exception caught");
> 	}
> }
> 
> I know that error2() is being called and the exception is being thrown...
> but it's not being caught at all.
> 
> Does anyone have ANY ideas?

It works fine for me with GCC 3.0.4 on i686-pc-linux-gnu, but I
can't tell what I might have done differently.

Your code fragment isn't complete (it can't be compiled without
additional code added), and you don't say how you built your shared
object or how you know that error2 was called.  If you provide a
complete example, someone might be able to help.

Janis

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

* Throw/Catch not working in SO?
@ 2002-10-14 17:36 Charles Y. Kim
  2002-10-14 18:38 ` Janis Johnson
  0 siblings, 1 reply; 5+ messages in thread
From: Charles Y. Kim @ 2002-10-14 17:36 UTC (permalink / raw)
  To: gcc

Hi all,

I'm using some exception handling in a shared object, and while the
throw()/catch() works in both Windows and FreeBSD (using GCC 2.96), in Linux
(GCC 3.02 --enable-shared --enable-threads=posix) the throw is executed, and
the catch never happens.

For example... let's say I have the following code in the shared object...

void error() {
	throw(1);
}

void error2() {
	error();
}

void function() {
	try {
		if (blah)
			error2();
	}
	catch(...) {
		printf("exception caught");
	}
}

I know that error2() is being called and the exception is being thrown...
but it's not being caught at all.

Does anyone have ANY ideas?

Thanks.

- Charles


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

end of thread, other threads:[~2002-10-15  8:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-15  2:45 Throw/Catch not working in SO? Rob
  -- strict thread matches above, loose matches on Subject: below --
2002-10-14 17:36 Charles Y. Kim
2002-10-14 18:38 ` Janis Johnson
2002-10-14 18:39   ` Charles Y. Kim
2002-10-14 21:14     ` Fergus Henderson

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