Satendra Pratap <[EMAIL PROTECTED]> writes: > I can not control the disclaimer that is being appended by our office > mailserver . Hence resending the mail from my gmail account.
Thanks. > After all this I got down to breaking the problem into a > compiler/linker (or my understanding) issue. After the analysis I have > learned that when we put some global objects in C++ source files, > there comes a function like __GLOBAL__I_FirstGlobalVariableInFile in > object file. This function actually do the initialization of the > corresponding global object and also contain calls to constructors of > other global objects in the file. Now, it's the job of linker to > accumulate all __GLOBAL__I_<> symbols from all .o into an array (of > function pointers). The linker should (as per docs) create a symbol > named __CTOR_LIST__ that should point to starting of the array. (In my > __main I'm processing __CTOR_LIST__). However in the final executable > __CTOR_LIST__ is not created at all! Though the __GLOBAL__I_<> symbols > are linked into the final executable gracefully. (Yes I have added > CONSTRUCTORS command to my linker script) First I'll note that the a.out object file format is quite obsolete, and very few people use it these days. I am not surprised that you are having trouble with it. That said, there are two standard ways to gather constructors in a.out. The first way is to use collect2. collect2 should do the job if USE_COLLECT2 is defined when it is compiled. USE_COLLECT2 should be defined if use_collect2 is set in config.gcc, which normally happens for *-*-aout targets. collect2 will gather constructors by running nm on the .o file and looking for symbols which match the names found in is_ctor_dtor in collect2.c. See collect2.c. Note that you must use gcc to link in order to invoke collect2. The second way is to use the GNU linker. The GNU linker will collect constructors if they are properly marked with an N_SETT tag. gcc should do this for you if none of these preprocessor symbols are defined: TARGET_ASM_CONSTRUCTOR, USE_COLLECT2, CTORS_SECTION_ASM_OP, TARGET_ASM_NAMED_SECTION. See default_stabs_asm_out_constructor in varasm.c and TARGET_ASM_CONSTRUCTOR in target-def.h. So, some things you can do: * See if USE_COLLECT2 is defined when you build gcc. * See if collect2 is being run when you link with gcc. * Use the option -Wl,-debug to get debugging output from collect2. * Look at the assembler file for N_SETT tags (you should see a line with __CTOR_LIST__ and the number 22). Ian