Undef weak ref to _init/_fini causes DT_INIT/DT_FINI in DSO

Hans-Peter Nilsson hans-peter.nilsson@axis.com
Tue Apr 9 10:15:00 GMT 2002


But should it be that way?  Right now you get those DT_INIT and
DT_FINI tags, with 0 for the address (their d_ptr value).

To wit, if I create a shared library consisting only of (by way
of -fpic -nostdlib -nostartfiles -shared):

extern char _init[] __attribute__ ((__weak__));
void *f(void)
{
  return _init;
}

Should that shared library have a DT_INIT due to this weak
undefined reference?

I can't find anything conclusive in
<URL:http://www.caldera.com/developers/gabi/latest/ch5.dynamic.html>
which should be all the RTFM needed (other pointers welcome).

IMHO, there should be no DT_INIT or DT_FINI if there are only
(weak) undefined references.  Note that the d_ptr value isn't
relocated; it will stay 0 no matter what _init or _fini are in
other libraries at runtime.  (Even if it could, another
libraries _init or _fini shouldn't be used for this library.)

Of course, relying on behavior one way or the other is improper.
(Found in uClibc,  they say it's 0.9.10.)

(Place to patch: elflink.h:NAME(bfd_elf,size_dynamic_sections),
about line 3172.)

brgds, H-P



More information about the Binutils mailing list