http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46770
--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> 2010-12-09 17:55:41 UTC --- Another test: [...@gnu-6 pr46770]$ cat foo.c #include <stdio.h> int main () { printf ("main\n"); return 0; } [...@gnu-6 pr46770]$ cat foo1.c #include <stdio.h> static void init () { printf ("init_array\n"); } static void (*const init_array []) () __attribute__ ((used, section (".init_array"), aligned (sizeof (void *)))) = { init }; static void fini () { printf ("fini_array\n"); } static void (*const fini_array []) () __attribute__ ((used, section (".fini_array"), aligned (sizeof (void *)))) = { fini }; [...@gnu-6 pr46770]$ cat foo2.c #include <stdio.h> static void ctor () { printf ("ctor\n"); } static void (*const ctors []) () __attribute__ ((used, section (".ctors"), aligned (sizeof (void *)))) = { ctor }; static void dtor () { printf ("dtor\n"); } static void (*const dtors []) () __attribute__ ((used, section (".dtors"), aligned (sizeof (void *)))) = { dtor }; [...@gnu-6 pr46770]$ make gcc -O -fPIC -c -o foo.o foo.c gcc -O -fPIC -c -o foo1.o foo1.c gcc -O -fPIC -c -o foo2.o foo2.c gcc -shared -o libfoo2.so foo2.o gcc -o foo1 foo.o foo1.o libfoo2.so -Wl,-R,. gcc -shared -o libfoo1.so foo1.o gcc -o foo2 foo.o libfoo1.so foo2.o -Wl,-R,. gcc -o foo3 foo.o foo1.o foo2.o ./foo1 ctor init_array main fini_array dtor ./foo2 init_array ctor main dtor fini_array ./foo3 ctor init_array main fini_array dtor [...@gnu-6 pr46770]$