[Lazarus] RE : Dynamic loading of a custom sqlite library

Max Vlasov max.vlasov at gmail.com
Sat Jun 11 22:49:16 CEST 2011


On Sat, Jun 11, 2011 at 1:34 PM, Ludo Brands <ludo.brands at free.fr> wrote:

> The solution you propose to avoid the effect of loading dynamically a
> library which has already been marked for loading by the linker seems quite
> dangerous. Suppose the unit that caused the linker to include the library
> (call it lib1) executes some initialization routines. These will run in
> lib1. Now you load dynamically the same lib (lib2). From now on all calls
> to
> the library functions are executed in lib2.
>


Hmm. CMIIW, but let's look at an example. I took a  quote from sqlite3.inc
and from my own module

==== this one is from sqlite3.inc (lightly modified)
function sqlite3_open(filename: pchar;ppDb: ppsqlite3): cint; cdecl;external
Sqlite3Lib;

==== this one from my module
  Procs.DLLHandle := dlopen(PAnsiChar('mysqlite3.so'), RTLD_NOW  OR
RTLD_DEEPBIND);
 @Procs.SQLite3_Open := dlsym(Procs.DLLHandle, 'sqlite3_open');

I suppose that if I don't use RTLD_DEEPBIND, both (sqlite3_open and
Procs.SQLite3_Open) will point to the same address (what is not so bad), but
what worse they both internally will use the same global writable data (what
is actually bad). But with RTLD_DEEPBIND both (sqlite3_open and
Procs.SQLite3_Open) will get different addresses (maybe not, but it's safe
for code or read-only data), but they will definitely get different copies
of the global writable data they need. So any current module that uses
sqlite3 will use the unchanged, safe context, no matter what I loaded on the
second, third or whatever step as long as I use RTLD_DEEPBIND for them.

So what did you mean by saying 'dangerous'?

Max
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110612/ce6714d6/attachment-0003.html>


More information about the Lazarus mailing list