Re: -static-libgcc, static libstdc++.a, dynamically loaded so files and exception handling.

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

 



Bob Rossi <bob@xxxxxxxxxx> writes:

> I've got a main C++ executable that I am linking with 
> -static-libgcc and libstdc++.a. This works fine.
> I'm doing this to make linux distribution easier.
>
> I've also got a C shared object library which I load from the
> main executable. The C shared object library, has function pointers
> which get registered in it from the main executable. So this happens,
>   - the main executable loads the shared object
>   - the main executable sets function pointers in the shared object
>   - the main executable calls a function in the loaded shared object file
>   - the shared object file calls a function pointer getting back into
>     the main executable
>   - an exception is thrown from the main executable (nested in the call
>     stack of the shared object)
>   - the exception propogates through the shared object interface and
>     is caught in the main executable again.
>
> Is this use of -static-libgcc, libstdc++.a, shared objects and
> exceptions safe in all known configurations?
>
> I'm worried about this text from the gcc documentation related 
> to the static-ligcc option,
>    There are several situations in which an application should use
>    the shared libgcc instead of the static version.  The most common
>    of these is when the application wishes to throw and catch
>    exceptions across different shared libraries.  In that case, each
>    of the libraries as well as the application itself should use the
>    shared libgcc.
> although, I don't think what I'm doing is related to what this text
> is discussing.

What you describe is not safe in all known configurations.  There are
configurations where the unwind library invoked to throw the exception
will not be able to find the unwind information defined by the shared
library, which means that it will not be able to reliably unwind through
the functions in the shared library, and, in particular, will not be
able to run destructors for local variables defined in functions in the
shared library.

However, what you describe is safe on current versions of GNU/Linux.  It
is safe if 1) your linker supports the --eh-frame-hdr option (binutils
2.12 ; 2) your glibc provides the dl_iterate_phdr option; 3) your gcc
was configured to be aware of both these facts.  These facts have been
true for at least five years on GNU/Linux systems.

What is the range of configurations you have to consider?

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux