This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: __attribute__((constructor)) and order of calls
- From: Arunachalam G <arunachalam at deeproot dot co dot in>
- To: Gigi Sullivan <sullivan at sikurezza dot org>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Thu, 31 Oct 2002 17:39:51 +0530 (IST)
- Subject: Re: __attribute__((constructor)) and order of calls
- References: <20021024190540.GD892@kappei.pacana.org>
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.