This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: c++ exceptions in shared lib


"Martin v. Loewis" wrote:

> > I read (and experienced) that exceptions do not work in shared lib
> > on platform other than linux.
>
> I don't think this is true, in general. For example, sjlj exceptions
> should work everywhere. Of course, there is a high penalty with them.

I don't know what are sjlj exceptions.
But on solaris 5.7 using gcc 2.95.1, this little test:

foo.cc:
void foo() {
 throw 1;
}

main.cc:
#include <iostream.h>

extern void foo();

int main (int argc, char** argv)
{
 try {
  foo();
 }
 catch(...) {
  cerr << "caught" << endl;
 }
 cerr << "end." << endl;
 return 0;
}

gives:
Abort (core dumped)
when compiled:
g++ -c main.cc
g++ -c foo.c
ld -G -h libfoo.so -o libfoo.so foo.o
g++ main.o -L. -lfoo

and gives:
caught
end.

when it's
ar cru libfoo.a foo.o
g++ -static main.o -L. -lfoo

something worth noticing: when compiled like that:

g++ -shared -o libfoo.so foo.o

I get:
Text relocation remains                         referenced
    against symbol                  offset      in file
terminate(void)                     0x70        foo.o
terminate(void)                     0x58        foo.o
__cp_push_exception                 0x40        foo.o
int type_info function              0x2c        foo.o
__eh_alloc                          0x8         foo.o
__throw                             0x68        foo.o
__throw                             0x24        foo.o
__throw                             0x48        foo.o
ld: fatal: relocations remain against allocatable but non-writable
sections
collect2: ld returned 1 exit status


--
Stéphane Conversy
http://www-ihm.lri.fr/~conversy/
mailto:conversy@lri.fr




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]