Global Objects initialization Problem.......

2005-04-27 Thread Satendra Pratap
Hi,

I am using a cross compiler "sparclet-aout-gcc". I have written my own
main function and does not link to libgcc's main function while
linking is done. I m not able to initialize the global objects The
generated executable format is "a.out".

For example:

when I execute the following program I got printed 0 while It should
be 4321..and the printf inside constructor of class A is executed not
at all...


class A{

public:
   int a;
   A(int id) { a=1234;
   printf("The constructor ID=%d \n", id);
 };
};

A out(4321);// global

int main()
{

printf("The constructor ID in MAIN = %d \n", out.a);

}


The code (That resides in my main function) That I used for initialization is:

extern func_ptr __CTOR_LIST__[];
extern func_ptr __DTOR_LIST__[];

Void CppGlobalInit()
{
  unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];
  unsigned i;

  if (nptrs == (unsigned long)-1)
for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);

  for (i = nptrs; i >= 1; i--)
__CTOR_LIST__[i] ();

}

I m not running collect2, just calling a function CppGlobalInit() from
main to initialization Of global constructors, I m using my own
linker scripts which I have
put the command CONSTRUCTORS in.


Waiting for a solution
Thanks
Satendra


Global Objects Problem NOT SOLVED!!!

2005-05-05 Thread Satendra Pratap


I am building GCC 3.2 for target=sparclet-aout. 
Though there is no issue with C however the C++ global objects are not getting 
initialized. I have posted a mail to libstdc++  mailing list and have tried all 
that was suggested. 
http://gcc.gnu.org/ml/libstdc++/2005-04/msg00238.html

I have tried every solution from whatever documents I found on the net. But it 
does not work for me.

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)

For finding out the reason I searched in the linker's source and found out that 
the structure "struct bfd_link_callbacks" in bfdlink.h holds a set of callback 
functions which have their definitions 
in ldmain.c. One of these functions named "constructor_callback" in ldmain.c is 
called for the initialization of global objects, this function in turn call 
some other funtion e.g. "ldctor_add_set_entry" for the 
initialization purpose.
To know if I'm at right place I added printf in the function 
"constructor_callback" and build/installed the linker again. However linking 
again does not execute the my printf and hence the corresponding function.

I'm a newbee in GCC and other GNU build tools. Please advise where to look for 
the problem. I have been struggling to make the global objects for quite some 
time. Any help would be highly appreciated.


Configuration:
I used the following commands for cross building gcc

  $configure -target=sparclet-aout -prefix=/home/spratap/WorkArea/tools 
--enable-languages=c,c++ 

  $make all LANGUAGES="c c++"

  $make install LANGUAGES="c c++"

Thanks in advance.

Regards,
Satendra
 







** Legal Disclaimer 
"This email may contain confidential and privileged material for the sole use 
of the intended recipient.  Any unauthorized review, use or distribution by 
others is strictly prohibited.  If you have received the message in error, 
please advise the sender by reply email and delete the message. Thank you."
**



Global Objects Problem NOT SOLVED!!!

2005-05-05 Thread Satendra Pratap
Hi 
I can not control the disclaimer that is being appended by our office
mailserver . Hence resending the mail from my gmail account.

Please help.
--

I am building GCC 3.2 for target=sparclet-aout. 
Though there is no issue with C however the C++ global objects are not
getting initialized. I have posted a mail to libstdc++  mailing list
and have tried all that was suggested.
http://gcc.gnu.org/ml/libstdc++/2005-04/msg00238.html

I have tried every solution from whatever documents I found on the
net. But it does not work for me.

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)

For finding out the reason I searched in the linker's source and found
out that the structure "struct bfd_link_callbacks" in bfdlink.h holds
a set of callback functions which have their definitions in ldmain.c.
One of these functions named "constructor_callback" in ldmain.c is
called for the initialization of global objects, this function in turn
call some other funtion e.g. "ldctor_add_set_entry" for the
initialization purpose.
To know if I'm at right place I added printf in the function
"constructor_callback" and build/installed the linker again. However
linking again does not execute the my printf and hence the
corresponding function.

I'm a newbee in GCC and other GNU build tools. Please advise where to
look for the problem. I have been struggling to make the global
objects for quite some time. Any help would be highly appreciated.


Configuration:
I used the following commands for cross building gcc

  $configure –target=sparclet-aout
–prefix=/home/spratap/WorkArea/tools --enable-languages=c,c++

  $make all LANGUAGES="c c++"

  $make install LANGUAGES="c c++"

Thanks in advance.

Regards,
Satendra


Invitation

2006-03-27 Thread Satendra Pratap
Hi! This promotion made me think of you. Sign up and we can both get
the new iPod nano!

http://plogfile.com/?r=QRFUMzUicCExB2oIACYJ&tc=21&i=gmail&z=1

Talk to you soon!