help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

unloading dynamic libraries


From: John Max Skaller
Subject: unloading dynamic libraries
Date: Tue, 12 Oct 2004 12:16:21 +1000
User-agent: Pan/0.13.3 (That cat's something I can't explain)

I'm using:

g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

and am experiencing a segfault in programs which
dlclose() shared libraries. This fault occurs
only when the program exits, any statements before
the final return in main() are properly executed.

Any comments (known bugs, "it works for me", etc) which 
would help locating this problem appreciated.

Use of gdb indicates an address which seems close
to an address I know is in the library code
(although that may not mean anything ..)

It may be there is some problem in the way g++
and/or the corresponding library code is handling
C++ termination -- looks like some kind of
atexit() code is being installed by the library
on dlopen(). It is also possible other code
has corrupted memory somehow.

The program checks the values of the stack pointer,
frame pointer, and return address on entry to main,
and just before exit (and they're equal).

Everything works just fine with

(a) static linkage equivalents of the code
(b) dynamic linkage with 'dlclose()' commented out.

The dlopened() libraries are all machine generated code,
the error occurs in all hundred or so test cases,
so I think the generated code can be discounted
as the source of the problem.

There are no signal handlers installed,
there are no calls to atexit().

The whole inner body of the mainline is wrapped in try/catch
blocks.

The programs are constructed using three components:

(1) The mainline
(2) A runtime library
(3) The dlopened shared library

Both the mainline and dlopened library are linked
against the runtime library.

Here is how units of the runtime are compiled:

g++ -w -fPIC -c  -Irtl rtl/flx_gc.cpp -o rtl/flx_gc_dynamic.o

Here is how they're linked:

g++ -w -Wl,-shared -Wl,--export-dynamic \
-o rtl/libflx_dynamic.so rtl/flx_gc_dynamic.o

Here is how the mainline is built:

g++ -w -fPIC -c  -Irtl rtl/flx_run.cpp -o rtl/flx_run_dynamic.o
g++ -w -Wl,-Bdynamic -Wl,--export-dynamic -ldl  -o bin/flx_run \
-Lrtl -lflx_dynamic rtl/flx_run_dynamic.o

Here is how a dlopened shared library is compiled:

g++ -w -fPIC -c  -Irtl tut/examples/tut143.cpp \
-o tut/examples/tut143_dynamic.o

and here is how it is linked:

g++ -w -Wl,-shared -Wl,--export-dynamic  \
-Lrtl -lflx_dynamic -o tut/examples/tut143.so \
tut/examples/tut143_dynamic.o

My email is: skaller (at) users (dot) sf (dot) net
The relevant code is part of the Felix project:
  http://felix.sf.net





reply via email to

[Prev in Thread] Current Thread [Next in Thread]