This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Shared library initializers


On May  3, 2001, Carlo Wood <carlo@alinoe.com> wrote:

> On Thu, May 03, 2001 at 11:05:27AM -0300, Alexandre Oliva wrote:
>> On May  3, 2001, Jeff Parker <JEFFREY.H.PARKER@saic.com> wrote:
>> > How do I the same thing using 'gcc' and/or 'ld' under LINUX?
>> 
>> Give the function the ``constructor'' attribute, or name it _init(),
>> or use the `-init SYMBOL' linker switch.

> Using the 'constructor' attribute doesn't garantee that this is the
> FIRST function to be called, prior to any other constructor of static
> and global objects, is it?

Nope.  See the init_priority attribute.

> Exporting a function _init() doesn't work for me:

> It is not easy to get rid of the /usr/lib/crti.o

Yep, _init() is defined by crti.o/crtbegin.o, and getting rid of it
would result in not having functions marked as constructors called,
and not having dynamic initializers executed.  I.e., you don't want to
override it.

> Is there a way to call _init of a specific library?

It's called implicitly, so you don't want to call it explicitly
again.  If you did, you could use dlsym to get the address of the
symbol, assuming the library was linked with -export-dynamic and you
had dlopen()ed it.

> How does that work anyway, when every shared library defines a
> global function _init?.

_init() is not exported, I suppose.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]