Hello :

            Anyone tell some thing about __CTOR_LIST__,__CTOR_END__,__DTOR_END__,__DTOR_END__?

            Seems that I need to use those function pointers to perform static variables’  initialization in __main. But I am not sure how they work with compiler . I copy a piece of code from gcc source libgcc.c to my lib source :


            typedef void(*func_ptr)(void);

func_ptr __CTOR_END__[1] __attribute__((section(".ctors"),  aligned(sizeof(func_ptr))))

                              = { (func_ptr) 0 };

void __attribute__((used)) __do_global_ctors_aux (void){

 func_ptr *p;

 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)

        (*p) ();


void __main()


static int initialized;

 if (! initialized){

initialized = 1;

//        __do_global_ctors ();





In my debugger ,I found  __CTOR_END__ - 1 points to value 0xff , so __do_global_ctors_aux() did nothing . The map file shows:


            0x004080d4                ___CTOR_LIST__ = .

                0x004080d4                __CTOR_LIST__ = .

                0x004080d4        0x4 LONG 0xffffffff



 .ctors         0x004080d8        0x4 D:\obj\_gnu_ix86.dbg\lib\libc.lib(libgcc.o)

                0x004080d8                __CTOR_END__

Seems that initialization list is empty but address 0x004080dc point to a wrapped  __static_initialization_and_destruction__ call which seems like what I want . What should I do ?


I wonder how the compiler considers the four variables , how it assigns static variables’ constructors or destructor to  the 4 points . Could anyone tell me or show me some documents or codes about that .

I am working on win2k ,mingw gcc3.1 ,target is ix86.