Discussion:
__attribute__((constructor)) and order of calls
Gigi Sullivan
2002-10-24 19:05:40 UTC
Permalink
Aiee :)

Hello!

Let suppose that I've 2 or more functions which are "characterized"
by the __attribute__((constructor)) attribute.

I'm just wondering if there's a clean way to know the routines' order
of call.

Does the same rule, if any, apply to destructor attribute as well ?

TIA, bye

-- gg sullivan
--
Lorenzo Cavallaro `Gigi Sullivan' <***@sikurezza.org>

Until I loved, life had no beauty;
I did not know I lived until I had loved. (Theodor Korner)
Arunachalam G
2002-10-31 12:09:51 UTC
Permalink
Hi,
Post by Gigi Sullivan
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.

Loading...