This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
constructor and destructor priority
- From: =?big5?b?RG91ZyBLd2FuICjD9q62vHcp?= <dougkwan at google dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 25 Feb 2010 22:42:05 -0800
- Subject: constructor and destructor priority
Hi,
The gcc manual defines ordering of constructors with priority
defined by __attribute__((constructor(priority)) but it does not say
anything about the ordering of a constructor with priority and one
without. For example,
#include <stdio.h>
void c () __attribute__((constructor));
void c200 () __attribute__((constructor(200)));
void d () __attribute__((destructor));
void d200 () __attribute__((destructor(200)));
void c () { puts("c"); }
void c200() { puts("c200"); }
void d () { puts("d"); }
void d200() { puts("d200"); }
int
main()
{
return 0;
}
On x86_64, I get the following result by compiling this with gcc-trunk
and running it.
c200
c
d
d200
On ARM with gcc-4.4.3, I get this
c200
c
d200
d
The difference is due to use of different initialization mechanism.
We have .ctors and .dtors on x86 and .init_array and .fini_array on
ARM. They are handled a little differently by ld. My question is
whether this is a specified behaviour or not. If so, could someone
point me to the definition?
-Doug