[LCP]Dynamic libraries and plugins
Joachim Bauernberger
bj at gmx.net
Mon Jun 24 21:17:05 UTC 2002
Hi,
On Monday 24 June 2002 12:27, Vincent Penquerc'h wrote:
> > If I use a
> > function from a library that's not compiled INTO my program,
> > how does my
> > program use of it? After all, if this is the case, then it
> > would have
> > to lookup a specific library from disk. So is there some
>
> A program is linked to the shared (dynamic) libraries it
> uses (.so files). The .so files are just not included in
> the final elf (or whatever exe format you happen to use).
> At load time (hence dynamic), the necessary shared libs
> are looked up (you can find out what foo needs by running
> "ldd foo") and loaded if not already. If several programs
> need it, they all have read/execute access on the
> appropriate pages, so the lib is loaded only once in
> memory (hence shared).
> The load code does some load time linking, which I suspect
> (but am not sure) boils down to replacing in the code the
> addresses of jumps to the lib routines by the ones which
> corresponds to the address the shared lib is loaded at.
>
> You can do this by hand if you want to, but you'll have to
> use function pointers: lookup dlopen, dlsym and friends.
> This is how you can load a library at runtime. Handy for
> things like drivers, or user customization libs.
I have a also a question regarding dlopen and friends (and when it would
make sense to use them)....
Say I have a program which is executed often (maybe even several times a
second) with many different options.
Due to soooo many options would it make sense to put different parts of
the code into seperate shared libs and call dlopen() by hand?
It would make the size of the binary smaller and many features which are
not needed are therefore never loaded no?
I specially think about saving initialization time of a program...
I.e. a virus scanning library would take a very long time to initilaize
itself since it needs to load (tens of) thousands signatures into
memory. So if one would have the virusscanning feature turned off the
program would therefore not waste time on startup trying to locate the
library no? Would it make sense to modularize a program this way in
order to save resources??
Thanks,
Joachim Bauernberger
>
> --
> Vincent Penquerc'h
>
--
http://mXscan.org/pgp/joachim.html
More information about the linuxCprogramming
mailing list