Global Constructors and Shared Libraries

Jeffrey A Law law@cygnus.com
Mon Jun 26 08:41:00 GMT 2000


  In message < 200006260724.JAA00859@loewis.home.cs.tu-berlin.de >you write:
  > > So collect should emit some "global initializer" into the library that
  > > __main can invoke, and therefore invoke each constructor in the library?
  > 
  > As I said: You should rather check whether you can have the system
  > linker collect things, e.g. by means of special sections.
The HPUX system linker does sections, but it's handling of initializers is
fundamentally broken (it's been years since Jason & I worked on this stuff,
so I don't remember the details).

I'd be surprised if the MPE linker's behavior is significantly different
than the HPUX linker since they're built from the same sources.

  > In write_c_file_stat, functions _GLOBAL__FI_<output file> are generated,
  > together with optional functions _GLOBAL__
Right.  The _GLOBAL__FI_<output_file> is the initializer for the shared
library <output_file> as a whole.

The following is how things work on SOM systems (32bit HPUX, MPE):

  When a shared library is listed on the link line for a user program that
  shared library initializer will be added to the main programs's list of
  ctors to fire out of __main.

  When a shared library is loaded at runtime via dl_open/shl_open calls, it
  is the program's responsibility to use shl_findsym to get a pointer to the
  library's initializer routine and call it.


jeff




More information about the Gcc mailing list