Shared library loading, please help me

Ian Lance Taylor ian@airs.com
Thu Mar 10 16:03:00 GMT 2005


matteo.pampolini@seleniacomms.com writes:

> just a stupid question: I noticed that the _init() function of a shared
> library is called every time
> an app that uses the library is launched, even though the library was
> already loaded in memory.
> 
> Then, if I have a shared library that must perform some hardware
> initialization only once, how
> can I check this for example with an "initialized" variable? Because I
> verified that every time I
> load the library the variable is set to its default value.

You have some misconception about Unix processes.  Every Unix process
executes in a separate memory space.  The fact that a shared library
was initialized in one memory space means nothing to another process
in another memory space.

If you want to do hardware initialization in a shared library, and you
want to do it only once, then you need to use some sort of IPC
mechanism, such as semaphores, a server process, a file system lock,
etc.  This is a general Unix programming question, not a binutils
question.

Ian



More information about the Binutils mailing list