Linux Exclusions from a Shared Object (.so)

I have a test program called ftest. It downloads .so files containing the tests and runs the tests that it finds there. One of these tests downloads and runs .so, which contains the Postgres database driver for our O / RM.

When the Postgres driver throws an exception that is defined in this .so file (or the one to which it is bound, but ftest does not refer to) and falls into the test environment, the exception destructor calls segfault.

This segfault occurs whenever a compiled exception is found in a .so that has been dynamically loaded (using dload).

Things like this work fine on Windows with the same architecture. We really do not want to limit ourselves to using exceptions from the main libraries only - add-ons should be free to create our own exception classes and their normal operation.

Exceptions are subclasses of std :: exception. Sometimes exceptions can be defined in libraries (for example, libpqxx), which means that exceptions are sometimes also beyond our control.

Exceptions are thrown using:

throw exception_class( exception_arguments ); 

And caught with:

 catch ( std::exception &e ) { // handler code } 

Is there any special compiler option needed for it to work? Do we need to switch to an exception through throw new exception_class( args ) (we really don't want to do this)?

+4
source share
1 answer

Assuming you are using gcc -

Add -Wl, -E when creating the dlload () executable call. It exports all standard type characters from the executable, which should allow RTTI (if an exception is detected) to work correctly.

VC ++ uses a string compared to matchinfo, and results in a slower dynamic_quality <> etc., but smaller binary files. g ++ uses a pointer.

I ran into the same problem when trying to use the pure virtual interface classes implemented at boot time .so.

There are several articles related to an object floating around on the net.

hope this helps, Hayman.

+6
source

Source: https://habr.com/ru/post/1286326/


All Articles