.init/.fini section question

Ian Lance Taylor iant@google.com
Wed Apr 7 14:42:00 GMT 2010


"Darryl L. Miles" <darryl-mailinglists@netbauds.net> writes:

> First where is the best source of documentation over ELF features that
> can be used by DSOs ?

Excellent question.


> * The dynamic linker serializes all invocations to an individual DSOs
> .init/.fini pointers (clarification covered in next 3 points).

Invocations are serialized yes, but not because of the dynamic linker.
The dynamic linker simply runs the code that the DT_INIT and
DT_INIT_ARRAY dynamic tags point to.

>   * That protection is provided between pointers of a single DSOs,
> i.e. they are fired in order of the ELF section synchronously.

Yes.

>   * That protection is provided between two (or more) independent
> threads causing the same DSO to be loaded.  i.e. the dynamic linker
> provides a mutex around the loading procedure and each user that is
> increasing the reference count gets to do their thing in turns.

Yes.

>   * This results in the .init/.fini pointers conforming to a
> single-threaded model (which is being enforced by the dynamic linker,
> even if the outside world is a multi-threaded enviroment).

Yes.

> * That each loading the DSO fires the .init/.fini, meaning each time
> the reference count inside the dynamic linker increments we always get
> the callbacks fired (for example through dlopen()).

No, if you dlopen the same DSO twice without dlclosing it in between,
the DT_INIT tags will only get run once.

> * Does the .init/.fini method have a way of asking the dynamic linker
> for its own handle/reference and what information does the dynamic
> linker make available through that.

I don't know of a way to do this.  There may be one.

Ian



More information about the Gcc-help mailing list