Re: late binding during exception handling



ben mitch wrote:
hi

we are currently porting an application to linux and are having a
problem. i'm no expert on linkage etc., least of all under linux, but it
appears to be a symbol-resolution problem, possibly related to lazy/late
binding of symbols in a shared library. the layout is

manager (executable)
core.so
process.so

and the problem arises as follows:

* start manager
* manager calls function exported from process.so to create an object X
* manager spawns a new worker thread (posix)
* worker thread calls member function of X
* member function of X throws a custom exception E, defined in core.so
* exception propagates back up to manager (in worker thread)
* exception type is unrecognised (i.e. is caught by catch(...))

currently, we catch the unknown exception, wrap it up in a nice
exception, and this eventually returns us to prompt, with information
lost since we never saw the actual exception thrown by process.
interestingly, if we call the manager to do the same thing again without
rebuilding (and again and again), on all subsequent calls the manager
recognises the thrown exception correctly, which is what makes me think
that binding is not getting done in time.

i thought (hope this doesn't sound too naive) that maybe during
exception handling it was already too late to bind to the exception
symbols in core, and hence the first exception thrown has to be handled
before it is bound. just a wild guess, perhaps someone has something
better!

all is written in C++, compiled using gcc (details below). compiler
switches are as follows:

core:
-pthread -O3 -ffast-math -Werror -fPIC -shared --export-dynamic

manager statically-linked component modules:
-pthread -O3 -ffast-math -Werror -fPIC

manager executable build:
-fPIC -ansi -D_GNU_SOURCE -pthread -O3 -ffast-math -DNDEBUG -pthread
-shared -m32 --export-dynamic

process:
-pthread -O3 -ffast-math -Werror -fPIC -shared

platform info:

MACHTYPE=i586-mandrake-linux-gnu
-bash-2.05b$ uname -a
Linux xxx.xxx.xxx.xxx 2.4.22-10mdk #1 Thu Sep 18 12:30:58 CEST 2003 i686
unknown unknown GNU/Linux
-bash-2.05b$ gcc --version
gcc (GCC) 3.3.1 (Mandrake Linux 9.2 3.3.1-2mdk)


sorry if i left anything out, let me know. and thanks in advance for any
help you can offer.

cheers
ben


For correct operation, C++ must be Compiled and Linked
with 'g++', not 'gcc', eg:

// compile 'manager' source files
g++ -c a.cpp
g++ -c b.cpp
...

// compile 'core' source files
g++ -c -fPIC -pthread d.cpp
g++ -c -fPIC =pthread e.cpp
...

// compile 'process' source files
g++ -c -fPIC -pthread f.cpp
g++ -c -fPIC =pthread g.cpp
...

// link 'core' shared lib (does not depend on 'process')
g++ -ocore.so -fPIC -pthread d.o e.o

// link 'process' shared lib (depends on 'core')
g++ -oprocess.so -fPIC -pthread f.o g.o -lcore

// link source into executable 'manager', being
// sure to specify the req'd libs in the correct
// order
g++ -o manager a.o b.o -lprocess -lcore

Since the are no Windows style IMPLIB's in Linux,
the 'core' and 'process' shared libs can NOT depend on
each other at compile/link time (ie. if 'process' calls
functions in 'core', then 'core' can NOT call functions
in 'process' - that would be a problematic 'circular
reference').

You'll get additional help on the correct compile/link
switches in the g++ newsgroup:

gnu.g++.help

.



Relevant Pages

  • Re: Handling unhandled exceptions
    ... Just as Jeroen pointed out, as a library, your responsibility is ... throwing the exception for bad condition. ... Microsoft Online Community Support ... Please feel free to let my manager know what you think of the ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Only one core working
    ... Device manager shows two processors ... Sisoft Sandra shows one processor (one core) ... Have updated ASUS Bios to latest 507, ... Yet only one chart appears on Task Manager graph, ...
    (microsoft.public.windowsxp.hardware)
  • late binding during exception handling
    ... i'm no expert on linkage etc., least of all under linux, but it appears to be a symbol-resolution problem, possibly related to lazy/late binding of symbols in a shared library. ... manager (executable) ... member function of X throws a custom exception E, ... currently, we catch the unknown exception, wrap it up in a nice exception, and this eventually returns us to prompt, with information lost since we never saw the actual exception thrown by process. ...
    (comp.os.linux.development.apps)
  • Re: HLA Stdlib v2.2 is now available.
    ... HLA code. ... Do you really think I post this code when it doesn't compile? ... The exception handling semantics are completely wrong. ...
    (alt.lang.asm)
  • Re: Compilers that do implement C++ Exception Specifications
    ... They aren't checked at compile time. ... why arent exception specifications "compile time type safety for excpt ... code isnt forcely filled with exception handling code. ...
    (comp.lang.cpp)