__attribute__((constructor)) and order of calls
Arunachalam G
arunachalam@deeproot.co.in
Thu Oct 31 04:11:00 GMT 2002
Hi,
> Let suppose that I've 2 or more functions which are "characterized"
> by the __attribute__((constructor)) attribute.
>
The functions which has attribute constructor will all be grouped in
__CTORS_LIST_ and those has destructor attribute will be grouped in
__DTORS_LIST_
while the program starts the function __do_global_ctors_aux which in .init
section will call the constructors starting from the tail of
__CTORS_LIST_ .
while the program ends the functions __do_global_dtors_aux which is in
.fini section will call the destructors from the head of __DTORS_LIST_ .
for eg.
...
static void f1() __attribute__ ((constructor));
static void f2() __attribute__ ((constructor));
static void f3() __attribute__ ((constructor));
static void f2() { ...; }
static void f1() { ...; }
static void f3() { ...; }
...
the order of call will be f3, f1, f2. the order will be reversed in case
of destructors.
--
arun.
More information about the Gcc-help
mailing list