calling function in .init and .fini gives problem

Zack Weinberg
Fri May 21 04:29:00 GMT 2004

"mohanlal jangir" <> writes:

> Thanks for your replies. Attributes "constructor" and "destructor" works
> very well. Does it mean attribute "constructor" puts the given data in .init
> section (similarly for destructor and .fini)? And why it does not work when
> I try to put the data by specifying __section__(".init")?

The runtime library expects the .init and .fini sections, and the
closely related .ctors and .dtors sections, to contain certain
specific things.  When you use __attribute__((constructor)), the
compiler puts the correct things in these sections.  When you use
__attribute__((section(".init"))), the function body gets dumped into
the .init section, which is decidedly the _wrong_ thing to put there.
Hence, attribute constructor works and attribute section ".init"


More information about the Gcc mailing list