This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]