I am looking at the C PlusPlus page, having just updated to GCC 4.3.0, specifically the 'Constructors' part, stating that global object constructors are found in the elf section 'ctors*', which is what I have always used. I used a construction function something along the following lines:
Code: Select all
void Construct()
{
/* construct global/static objects */
void (**constructor)() = &start_ctors;
void (**lastctor)() = &end_ctors;
kprintf("Calling %#08x to %#08x\n", constructor, lastctor);
if((constructor)>=(lastctor)) return;
do
{
kprintf("Constructor (at %#08x) calling EIP %#08x\n", constructor, *constructor);
(*constructor)();
}while((*++constructor)<(*lastctor));
}
When compiling with G++ 4.3.0, the whole lot seems to be misaligned by a byte - in other words, I have to add one byte to 'start_ctors' in order to get things running. The value of the additional byte is zero. I am aware that GCC sometimes sets the first integer in the constructor list as the number of constructors present, but think that if it does this the integer should be a full 4 bytes?
Is there any reason why it should be exhibiting this new behaviour (my previous compiler was g++ 4.2.2 i586 elf - all that has changed is the version), or has something gone wrong with my linking?
Cheers,
Adam